/**
  * Sync the stores data to wechat
  */
 public function actionPush()
 {
     $channelIds = $this->getParams('channelIds');
     $storeIds = $this->getParams('storeIds');
     $isAllStores = $this->getParams('isAllStores', false);
     if (empty($channelIds) || empty($storeIds) && !$isAllStores) {
         throw new BadRequestHttpException(Yii::t('common', 'parameters_missing'));
     }
     $result = ['finished' => true];
     $token = Token::getToken();
     $accountId = $token->accountId;
     if ($isAllStores) {
         $stores = Store::find()->select(['_id'])->where(['accountId' => $accountId, 'isDeleted' => Store::NOT_DELETED])->all();
         if (!empty($stores)) {
             $storeIds = [];
             foreach ($stores as $store) {
                 $storeIds[] = (string) $store->_id;
             }
         }
     }
     $args = ['accountId' => (string) $accountId, 'channels' => $channelIds, 'storeIds' => $storeIds, 'userId' => (string) $token->userId, 'description' => 'Direct: Sync the stores data to wechat'];
     $token = Yii::$app->job->create('backend\\modules\\channel\\job\\StoreSync', $args);
     $result = ['finished' => false, 'token' => $token];
     return $result;
 }
 /**
  * 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;
 }
 /**
  * 店铺消费曲线图
  * @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);
 }