Пример #1
0
 public function perform()
 {
     $args = $this->args;
     $accountId = new MongoId($args['accountId']);
     $storeId = new MongoId($args['storeId']);
     $store = Store::findByPk($storeId);
     if (!empty($args['location'])) {
         // create new store location
         $location = $args['location'];
         if ($this->_addNewLocation($location, $accountId)) {
             $storeLocation = new StoreLocation();
             $storeLocation->_id = $store->_id;
             $storeLocation->name = $store->name;
             $storeLocation->parentName = $location['district'];
             $storeLocation->level = StoreLocation::LOCATION_LEVEL_STORE;
             $storeLocation->accountId = $accountId;
             $storeLocation->save();
         }
     } else {
         if (!empty($args['oldLocation']) && !empty($args['newLocation'])) {
             // update store location
             $oldLocation = $args['oldLocation'];
             $newLocation = $args['newLocation'];
             StoreLocation::updateAll(['name' => $store->name, 'parentName' => $newLocation['district']], ['_id' => $store->_id]);
             $this->_updateLocation($oldLocation, $newLocation, $accountId);
         } else {
             if (!empty($args['removeLocation'])) {
                 // delete store location
                 $location = $args['removeLocation'];
                 StoreLocation::deleteAll(['_id' => $storeId]);
                 $this->_removeOldLocation($location, $accountId);
             }
         }
     }
     //update store name
     if (!empty($args['newStoreName'])) {
         //update storeLocation name
         StoreLocation::updateAll(['name' => $args['newStoreName']], ['_id' => $storeId]);
         //update couponLog
         CouponLog::updateAll(['store.name' => $store->name], ['_id' => $storeId]);
     }
     //update coupon store name
     $this->_updateCouponStroeInfo($store);
 }