public function actionView($id) { $id = new MongoId($id); $store = Store::findByPk($id); if (empty($store)) { throw new BadRequestHttpException(Yii::t('common', 'data_error')); } $location = $store->getStoreLocation(); $result = $store->toArray(); $result['location'] = $location; $accountId = $this->getAccountId(); $result['storeGoods'] = StoreGoods::getTotal($id, $accountId); $result['staff'] = Staff::getTotal($id, $accountId); return $result; }
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); }
public function actionCreate() { $goods = $this->getParams('goods'); $storeId = $this->getParams('storeId'); $accountId = $this->getAccountId(); if (empty($goods) || empty($storeId)) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } $storeId = new \MongoId($storeId); $store = Store::findByPk($storeId); if (empty($store)) { throw new InvalidParameterException(Yii::t('common', 'data_error')); } $productIds = []; foreach ($goods as $item) { if (!StoreGoods::validatePrice($item['price'])) { throw new InvalidParameterException(Yii::t('store', 'price_error')); } $productIds[] = new \MongoId($item['productId']); } $storeGoodsCount = StoreGoods::countByProductId($productIds, $storeId); if ($storeGoodsCount > 0) { throw new InvalidParameterException(Yii::t('store', 'goods_exists')); } $storeGoods = []; foreach ($goods as $item) { $product = Product::findByPk($item['productId']); if (empty($product)) { throw new InvalidParameterException(Yii::t('common', 'data_error')); } $category = $product->category; $pictures = ArrayHelper::getColumn($product->pictures, 'url', false); $pictures = array_slice($pictures, 0, 5); $storeGoods[] = ['storeId' => $storeId, 'categoryId' => $category['id'], 'productName' => $product->name, 'sku' => $product->sku, 'productId' => $product->_id, 'pictures' => $pictures, 'status' => StoreGoods::STATUS_OFF, 'offShelfTime' => new \Mongodate(), 'price' => !empty($item['price']) ? floatval($item['price']) : 0.0, 'accountId' => $accountId]; } if (StoreGoods::batchInsert($storeGoods)) { return ['message' => 'OK', 'data' => null]; } else { throw new ServerErrorHttpException(Yii::t('common', 'save_fail')); } }
/** * View a store qrcode detail * * <b>Request Type</b>: GET<br/><br/> * <b>Request Endpoint</b>:http://{server-domain}/api/offlinestore/qrcode/view?storeId=551362dbc0d0803ad7995b66<br/><br/> * <b>Response Content-type</b>: application/json<br/><br/> * <b>Summary</b>: This api is used to view qrcode detail. * <br/><br/> * * <b>Request Params</b>:<br/> * channelId: string<br/> * <br/><br/> * * <b>Response Params:</b><br/> * array, json array to querie qrcode detail information<br/> * <br/><br/> * * <br/><br/> * * <b>Response Example</b>:<br/> * <pre> * { * "msgType": "NEWS", * "content": { * "articles": [ * { * "title": "没有", * "description": "", * "url": "http://vincenthou.qiniudn.com/94b6e2756acb030f6f76f690.jpg", * "content": "<p>哈哈哈哈</p>" * } * ] * } * } * </pre> */ public function actionView() { $qrcode = $this->getQuery(); if (empty($qrcode['storeId'])) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } $storeId = new \MongoId($qrcode['storeId']); $store = Store::findByPk($storeId); if (!empty($store->wechat['channelId'])) { $channelId = $store->wechat['channelId']; $qrcodeId = $store->wechat['qrcodeId']; } if (!empty($store->weibo['channelId'])) { $channelId = $store->weibo['channelId']; $qrcodeId = $store->weibo['qrcodeId']; } if (!empty($channelId) && !empty($qrcodeId)) { $qrcode = Yii::$app->weConnect->getQrcode($channelId, $qrcodeId); if (!empty($qrcode['accountId'])) { return ['msgType' => $qrcode['msgType'], 'content' => $qrcode['content']]; } } }
/** * Get store detail statistic * * <b>Request Type</b>: GET<br/><br/> * <b>Request Endpoint</b>:http://{server-domain}/channel/offlinestore/store/analysis<br/><br/> * <b>Content-type</b>: application/json<br/><br/> * <b>Summary</b>: This api is used for getting store detail statistic * <br/><br/> * * <b>Request Params</b>:<br/> * storeId: string, the store id, required<br/> * startDate: string, the start date, such as '2015-01-01'<br/> * endDate: string, the end date, such as '2015-01-07'<br/> * <br/><br/> * * <b>Response Example</b>:<br/> * <pre> * { * "wechat": { * "statDate": ["2015-01-01", "2015-01-02", "2015-01-03", "2015-01-04", "2015-01-05", "2015-01-06", "2015-01-07"], * "scanNumber": [11, 15, 35, 89, 90, 80, 10], * "followNumber": [10, 10, 5, 8, 0, 8, 10] * }, * "weibo": { * "statDate": ["2015-01-01", "2015-01-02", "2015-01-03", "2015-01-04", "2015-01-05", "2015-01-06", "2015-01-07"], * "scanNumber": [11, 15, 35, 89, 90, 80, 10], * "followNumber": [13, 18, 34, 49, 30, 82, 20] * } * } * </pre> */ public function actionAnalysis() { $storeId = $this->getQuery('storeId'); $startDate = $this->getQuery('startDate'); $endDate = $this->getQuery('endDate'); if (empty($storeId)) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } $storeId = new MongoId($storeId); $store = Store::findByPk($storeId); if (empty($store)) { throw new BadRequestHttpException(Yii::t('channel', 'no_such_store')); } $dateCondition = ['startDate' => $startDate, 'endDate' => $endDate, 'type' => 'SCAN']; $keyMaps = ['scanNumber' => 'scan', 'followNumber' => 'subscribe']; $result = ['wechat' => [], 'weibo' => []]; if (!empty($store->wechat['channelId']) && !empty($store->wechat['qrcodeId'])) { $qrcodeData = Yii::$app->weConnect->getQrcodeTimeSeries($store->wechat['channelId'], $store->wechat['qrcodeId'], $dateCondition); $result['wechat'] = $this->formateResponseData($qrcodeData, $keyMaps, $startDate, $endDate); } if (!empty($store->weibo['channelId']) && !empty($store->weibo['qrcodeId'])) { $qrcodeData = Yii::$app->weConnect->getQrcodeTimeSeries($store->weibo['channelId'], $store->weibo['qrcodeId'], $dateCondition); $result['weibo'] = $this->formateResponseData($qrcodeData, $keyMaps, $startDate, $endDate); } return $result; }
public function extraFields() { return array_merge(parent::fields(), ['store' => function () { return Store::findByPk($this->storeId); }]); }
/** * Refined store location */ public function actionIndex() { $stores = Store::findAll([]); if (!empty($stores)) { foreach ($stores as $store) { if (!empty($location = $store->location)) { if (!empty($location['county'])) { unset($location['county']); $store->location = $location; $store->save(); } if (!empty($location['province']) && !empty($location['city']) && !empty($location['district'])) { $accountId = $store->accountId; $locationKeys = ['province', 'city', 'district']; $parentName = null; $storeLocation = StoreLocation::findByPk($store->_id); if (empty($storeLocation)) { $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(); } foreach ($locationKeys as $key) { $storeLocation = StoreLocation::findOne(['name' => $location[$key], 'accountId' => $accountId]); if (empty($storeLocation)) { // if store location doesn't exist, add it $storeLocation = new StoreLocation(); $storeLocation->_id = new \MongoId(); $storeLocation->name = $location[$key]; $storeLocation->parentName = $parentName; $storeLocation->level = $this->levelMap[$key]; $storeLocation->accountId = $accountId; $storeLocation->save(); } // current location name is the next's parent $parentName = $storeLocation->name; } } } } } $storeLocations = StoreLocation::findAll(['level' => StoreLocation::LOCATION_LEVEL_STORE]); if (!empty($storeLocations)) { foreach ($storeLocations as $storeLocation) { $findStoreLocation = Store::findByPk($storeLocation->_id); if (empty($findStoreLocation)) { $storeLocation->delete(); } } } foreach (array_reverse($this->levelMap) as $level) { $storeLocations = StoreLocation::findAll(['level' => $level]); if (!empty($storeLocations)) { foreach ($storeLocations as $storeLocation) { $accountId = $storeLocation->accountId; $findStoreLocation = StoreLocation::findOne(['parentName' => $storeLocation->name, 'accountId' => $accountId]); if (empty($findStoreLocation)) { $storeLocation->delete(); } } } } }
public function perform() { $args = $this->args; $accountId = new \MongoId($args['accountId']); $channels = $args['channels']; if (!empty($args['storeIds'])) { // Sync store data to wechat $userId = $args['userId']; $storeIds = $args['storeIds']; $storeData = []; foreach ($storeIds as $key => $storeId) { $storeId = new \MongoId($storeId); $store = Store::findByPk($storeId); $storeData[] = $store->toData(); } $failResult = []; foreach ($channels as $channelId) { try { $result = \Yii::$app->weConnect->addStore($channelId, $storeData); if (!empty($result['location_id_list']) && in_array(-1, $result['location_id_list'])) { foreach ($result['location_id_list'] as $index => $locationId) { if ($locationId === -1) { $failResult[] = ['channelId' => $channelId, 'storeId' => $storeIds[$index], 'storeName' => $storeData[$index]['business_name']]; } } } } catch (\Exception $e) { ResqueUtil::log($e); foreach ($storeData as $index => $store) { $failResult[] = ['channelId' => $channelId, 'storeId' => $storeIds[$index], 'storeName' => $store['business_name']]; } } } if (!empty($failResult)) { \Yii::$app->cache->set(Store::CACHE_PREFIX . $userId . Store::SYNC_TO_WECHAT, $failResult, Store::CACHE_EXPIRE_TIME); throw new \Exception('Sync store data to wechat failed.'); } } else { // Sync store data from wechat $account = Account::findByPk($accountId); $syncWechat = []; if (!empty($account->syncWechat)) { $syncWechat = $account->syncWechat; } $sizeCondition = ['offset' => static::STORE_START_NUM, 'count' => static::STORE_END_NUM]; foreach ($channels as $channelId) { $stores = \Yii::$app->weConnect->getStores($channelId, $sizeCondition); ResqueUtil::log($stores); if (!empty($stores['location_list'])) { foreach ($stores['location_list'] as $storeData) { $store = new Store(); $store->loadData($storeData); $store->accountId = $accountId; $store->save(); } } array_push($syncWechat, $channelId); } $account->syncWechat = $syncWechat; $account->save(); } }