| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace platform\controllers;
- use common\services\xhMerchantService;
- use Yii;
- use yii\data\Pagination;
- use common\models\xhShop;
- use common\models\xhWifi;
- use common\components\weixinUtil;
- use common\services\xhShopService;
- class ShopController extends PlatformController
- {
- /**
- * 待审核的门店列表
- */
- public function actionList(){
- $query = xhShop::find()->where(['<=', 'status', 0]);
- $countQuery = clone $query;
- $pages = new Pagination(['totalCount' => $countQuery->count()]);
- $models = $query->offset($pages->offset)->limit($pages->limit)->all();
- //dump($models);die;
- return $this->render('list', [
- 'models' => $models,
- 'pages' => $pages,
- ]);
- }
- /**
- * 审核门店,通过则向微信接口提交
- */
- public function actionCheckStore()
- {
- $id = Yii::$app->request->post('shopId');
- $xhShopService = new xhShopService();
- $weixinShopData = $xhShopService->getShopData($id);
- //向微信提交建立门店
- $shop = xhShopService::getById($id);
- $merchantId = $shop['merchantId'];
- $merchant = xhMerchantService::getById($merchantId);
- $weixinUtil = new weixinUtil($merchant);
- $data = $response = $weixinUtil->createStore($weixinShopData);
- $response = json_decode($response, true);
- if($response['errcode'] == 0){
- $shopId = $weixinUtil->getShopId($response['poi_id']);
- $shop['poiId'] = $response['poi_id'];
- $shop['shopId'] = $shopId;
- $shop['status'] = 1;
- //成功后更新数据库
- $re = xhShopService::updateById($id, $shop);//存入表xhShop
- $wifiData = ['shopId' => $shop['shopId'], 'createTime' => date('Y-m-d H:i:s', time())];
- xhWifi::add($wifiData);//初始化商家wifi
- }
- echo $data;
- Yii::$app->end();
- }
- }
|