ShopController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace platform\controllers;
  3. use common\services\xhMerchantService;
  4. use Yii;
  5. use yii\data\Pagination;
  6. use common\models\xhShop;
  7. use common\models\xhWifi;
  8. use common\components\weixinUtil;
  9. use common\services\xhShopService;
  10. class ShopController extends PlatformController
  11. {
  12. /**
  13. * 待审核的门店列表
  14. */
  15. public function actionList(){
  16. $query = xhShop::find()->where(['<=', 'status', 0]);
  17. $countQuery = clone $query;
  18. $pages = new Pagination(['totalCount' => $countQuery->count()]);
  19. $models = $query->offset($pages->offset)->limit($pages->limit)->all();
  20. //dump($models);die;
  21. return $this->render('list', [
  22. 'models' => $models,
  23. 'pages' => $pages,
  24. ]);
  25. }
  26. /**
  27. * 审核门店,通过则向微信接口提交
  28. */
  29. public function actionCheckStore()
  30. {
  31. $id = Yii::$app->request->post('shopId');
  32. $xhShopService = new xhShopService();
  33. $weixinShopData = $xhShopService->getShopData($id);
  34. //向微信提交建立门店
  35. $shop = xhShopService::getById($id);
  36. $merchantId = $shop['merchantId'];
  37. $merchant = xhMerchantService::getById($merchantId);
  38. $weixinUtil = new weixinUtil($merchant);
  39. $data = $response = $weixinUtil->createStore($weixinShopData);
  40. $response = json_decode($response, true);
  41. if($response['errcode'] == 0){
  42. $shopId = $weixinUtil->getShopId($response['poi_id']);
  43. $shop['poiId'] = $response['poi_id'];
  44. $shop['shopId'] = $shopId;
  45. $shop['status'] = 1;
  46. //成功后更新数据库
  47. $re = xhShopService::updateById($id, $shop);//存入表xhShop
  48. $wifiData = ['shopId' => $shop['shopId'], 'createTime' => date('Y-m-d H:i:s', time())];
  49. xhWifi::add($wifiData);//初始化商家wifi
  50. }
  51. echo $data;
  52. Yii::$app->end();
  53. }
  54. }