示例#1
0
 /**
  * @before _admin
  */
 public function info($id = null)
 {
     $this->seo(array("title" => "Publisher Edit"));
     $view = $this->getActionView();
     $publisher = User::first(["_id = ?" => $id, "type = ?" => "publisher", "org_id = ?" => $this->org->id]);
     if (!$publisher) {
         $this->_404();
     }
     $platforms = Platform::all(["user_id = ?" => $publisher->id]);
     $view->set("platforms", $platforms);
     $view->set("errors", []);
     if (RM::type() == 'POST') {
         $action = RM::post('action', '');
         switch ($action) {
             case 'account':
                 $fields = ['name', 'email', 'phone', 'country', 'currency', 'username'];
                 foreach ($fields as $f) {
                     $publisher->{$f} = RM::post($f);
                 }
                 $publisher->save();
                 $view->set('message', 'Account Info updated!!');
                 break;
             case 'password':
                 $old = RM::post('password');
                 $new = RM::post('npassword');
                 $view->set($publisher->updatePassword($old, $new));
                 break;
             case 'campaign':
                 $publisher->getMeta()['campaign'] = ['model' => RM::post('model'), 'rate' => $this->currency(RM::post('rate'))];
                 $publisher->save();
                 $view->set('message', 'Payout Info Updated!!');
                 break;
             case 'trackingDomain':
                 $tdomain = (array) RM::post('tdomain', '');
                 if ($tdomain && ArrayMethods::inArray($this->org->tdomains, $tdomain)) {
                     $publisher->getMeta()['tdomain'] = $tdomain;
                     $publisher->save();
                     $view->set('message', 'Added Tracking Domain for publisher');
                 } else {
                     $view->set('message', 'Invalid Request!!');
                 }
             case 'commadd':
             case 'commedit':
                 $comm_id = RM::post('comm_id');
                 if ($comm_id) {
                     $comm = Commission::first(['_id' => $comm_id, 'user_id' => $publisher->_id]);
                 } else {
                     $comm = new Commission(['user_id' => $publisher->_id]);
                 }
                 $comm->model = RM::post('model');
                 $comm->description = RM::post('description');
                 $comm->rate = $this->currency(RM::post('rate'));
                 $comm->coverage = RM::post('coverage', ['ALL']);
                 $comm->save();
                 $view->set('message', "Multi Country Payout Saved!!");
                 break;
         }
     }
     if (RM::type() === 'DELETE') {
         $action = RM::get("action");
         switch ($action) {
             case 'payoutdel':
                 unset($publisher->getMeta()['campaign']);
                 $publisher->save();
                 $view->set('message', 'Payout Deleted!!');
                 break;
             case 'commDel':
                 $comm = Commission::first(['_id' => RM::get("comm_id"), 'user_id' => $publisher->_id]);
                 if ($comm) {
                     $comm->delete();
                     $view->set('message', 'Payout Deleted!!');
                 } else {
                     $view->set('message', 'Invalid Request!!');
                 }
                 break;
             case 'afields':
                 $meta = $publisher->meta;
                 $publisher->removeFields();
                 unset($meta['afields']);
                 Db::updateRaw('users', ['_id' => Db::convertType($publisher->_id, 'id')], ['$set' => ['meta' => $meta]]);
                 $view->set('message', 'Data Removed!!');
                 break;
             case 'defaultDomain':
                 unset($publisher->getMeta()['tdomain']);
                 $publisher->save();
                 $view->set('message', 'Removed tracking domain!!');
                 break;
         }
     }
     $afields = Meta::search('customField', $this->org);
     $view->set('afields', $afields)->set("publisher", $publisher)->set("commissions", Commission::all(["user_id = ?" => $publisher->id]))->set("start", strftime("%Y-%m-%d", strtotime('-7 day')))->set("end", strftime("%Y-%m-%d", strtotime('now')))->set("d", Performance::total(['start' => $start ?? $publisher->created->format('Y-m-d'), 'end' => $end ?? date('Y-m-d')], $publisher));
 }