public function actionIndex() { $view = \Yii::$app->view; $view->params['moduleName'] = '主表盘'; // 入驻商家统计 $store = Store::getStoreStatusNum(); $waiting = 0; $approval = 0; $deny = 0; $disable = 0; foreach ($store as $v) { ${$v}['status'] = $v['num']; } // 充值统计 $recharge = Recharge::getRechargeStatusAmount(); $recharge_success_amount = 0; $recharge_success_num = 0; $recharge_wait_amount = 0; $recharge_wait_num = 0; foreach ($recharge as $v) { if ($v['status'] == 'success') { $recharge_success_amount = $v['amount']; $recharge_success_num = $v['num']; } elseif ($v['status'] == 'wait') { $recharge_wait_amount = $v['amount']; $recharge_wait_num = $v['num']; } } // 财务统计 return $this->render('index', ['waiting' => $waiting, 'approval' => $approval, 'deny' => $deny, 'disable' => $disable, 'recharge_success_amount' => $recharge_success_amount, 'recharge_success_num' => $recharge_success_num, 'recharge_wait_amount' => $recharge_wait_amount, 'recharge_wait_num' => $recharge_wait_num]); }
public function deleteQrcode($channelId, $qrcodeId) { //can not delete staff qrcode,if the qrcode is deleted,i can not update the template of qrcode when staff update his username $staffInfo = Staff::findOne(['qrcodeId' => $qrcodeId]); if (!empty($staffInfo)) { throw new InvalidParameterException(Yii::t('channel', 'delete_staff_qrcode_fail')); } //delete store qrcode Store::deleteStoreQrcode($channelId, $qrcodeId); }
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')); } }
/** * 店铺详情 * @return type */ public function actionInfo() { $view = \Yii::$app->view; $view->params['moduleName'] = '商家信息'; $storeId = intval(\Yii::$app->request->get('storeId', 0)); $store = Store::findOne(['storeId' => $storeId]); if (!$store) { return $this->redirect('/store/index'); } \Yii::$app->language = 'zh-CN'; $token = Token::getToken(); $user = \Yii::$app->user->id; $changestatusIdentity = EasyHelpers::dataEncrypt('changestatus,' . $user); $saleIdentity = EasyHelpers::dataEncrypt('sale,' . $user); $salestoreIdentity = EasyHelpers::dataEncrypt('salestore,' . $user); //销售 $total = StoreSale::getSaleTotal(); $pagination = new \yii\data\Pagination(['totalCount' => $total, 'defaultPageSize' => \Yii::$app->params['pageSize']]); $sales = StoreSale::getSale($storeId, $pagination->offset, $pagination->limit); return $this->render('storeinfo', ['store' => $store, 'token' => $token, 'changestatusIdentity' => $changestatusIdentity, 'salestoreIdentity' => $salestoreIdentity, 'saleIdentity' => $saleIdentity, 'sales' => $sales, 'pagination' => $pagination]); }
/** * 店铺审核 */ public function actionChangestatus() { $request = \Yii::$app->request; $identity = Identity::checkIdentity('changestatus', '/app-backend/backend/store/changestatus'); if (is_array($identity)) { return $identity; } $storeId = $request->_get('storeId', 0); $status = $request->_get('status', ''); $message = $request->_get('message', ''); if (!$storeId || !in_array($status, ['approval', 'deny', 'disable'])) { return ['code' => 1, 'msg' => '数据非法', 'data' => []]; } $userId = $identity; $res = Store::changeStatus($storeId, $status, $message, $userId); if ($res !== false) { return ['code' => 0, 'msg' => '操作成功', 'data' => ['status' => $res]]; } else { return ['code' => 2, 'msg' => '操作失败,请重试', 'data' => []]; } }
/** * 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 coupon about store from mobile * note: mobile only get some special modules */ public function actionCouponStore() { $params = $this->getQuery(); if (empty($params['couponId'])) { throw new InvalidParameterException(Yii::t('common', 'parameters_missing')); } $couponId = new MongoId($params['couponId']); $coupon = Coupon::findByPk($couponId); if (!empty($coupon)) { if ($coupon->storeType == Coupon::COUPON_ALL_STORE) { $stores = Store::find()->where(['accountId' => $coupon->accountId, 'isDeleted' => Coupon::NOT_DELETED])->orderBy(['_id' => SORT_DESC])->all(); $coupon->stores = Coupon::conver2couponStore($stores); } else { if (!empty($coupon->stores)) { foreach ($stores = $coupon->stores as &$store) { $store['id'] = (string) $store['id']; } ArrayHelper::multisort($stores, 'id', SORT_DESC); $coupon->stores = $stores; } } } return $coupon; }
/** * delete store data * @param $channelId,string */ public static function deleteStoreQrcode($channelId, $qrcodeId) { $channelInfo = Channel::getEnableByChannelId($channelId); if (empty($channelInfo->origin)) { throw new InvalidParameterException('invaild channelId'); } $field = $channelInfo->origin; $where = [$field . '.qrcodeId' => $qrcodeId]; Store::updateAll([$field => null], $where); }
/** * get qrcodeId name:struct array(qrcodeId=>value) * @param $qrcodeIds,array */ public static function getQrcodeName($qrcodeIds) { $data = []; //promotion qrcode only check in store and staff if (!empty($qrcodeIds)) { $where = Store::createStoreChannelCondition($qrcodeIds); $storeInfos = Store::findAll($where); $storeIds = []; if (!empty($storeInfos)) { $model = new Store(); $channels = $model->storeChannels; foreach ($storeInfos as $storeInfo) { foreach ($channels as $channel) { if (!empty($channel = $storeInfo->{$channel})) { $storeIds[] = $channel['qrcodeId']; $data[$channel['qrcodeId']] = $storeInfo->name; } } } } //get staff qrcode $staffIds = array_values(array_diff($qrcodeIds, $storeIds)); $where = ['qrcodeId' => ['$in' => $staffIds]]; $staffInfos = Staff::findAll($where); if (!empty($staffIds)) { foreach ($staffInfos as $staffInfo) { $name = ''; if (!empty($staffInfo->name)) { $name = $staffInfo->name; } $data[$staffInfo->qrcodeId] = '店员' . $name . '二维码'; } } } return $data; }
/** * 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(); } }
/** * 店铺消费曲线图 * @return type */ public function actionConsumedetail() { $view = \Yii::$app->view; $view->params['moduleName'] = '消费统计'; $storeId = \YIi::$app->request->get('storeId', 0); $store = []; if ($storeId) { $store = Store::find()->where(['storeId' => $storeId])->asArray()->One(); $store['consumes'] = Consume::getConsumeNum($storeId); $store['lastConsume'] = Consume::getLastConsume($storeId); } if (!$store) { return $this->redirect('/finance/consume'); } $data['store'] = $store; $data['token'] = Token::getToken(); return $this->render('consumedetail', $data); }