MerchantController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. namespace saas\controllers;
  3. use biz\merchant\classes\MerchantClass;
  4. use biz\merchant\services\MerchantExtendService;
  5. use biz\wx\classes\WxBaseClass;
  6. use biz\wx\classes\WxMiniBaseClass;
  7. use biz\wx\classes\WxOpenClass;
  8. use Yii;
  9. use biz\admin\services\AdminService;
  10. use biz\merchant\services\MerchantService;
  11. use common\components\util;
  12. use common\components\wxUtil;
  13. use common\services\xhMerchantService;
  14. class MerchantController extends BaseController
  15. {
  16. public $withoutLogin = ['bind-open'];
  17. //商家列表 shish 2019.12.20
  18. public function actionList()
  19. {
  20. $get = Yii::$app->request->get();
  21. $style = $get['style'] ?? MerchantClass::STYLE_RETAIL;
  22. $where = [];
  23. if (!empty($style)) {
  24. $where['style'] = $style;
  25. }
  26. $list = MerchantService::getMerchantList($where);
  27. util::success($list);
  28. }
  29. //获取当前登陆老板的帐号详情,官网购买套餐时使用 shish 2020.1.11
  30. public function actionLoginAccount()
  31. {
  32. $userId = $this->userId;
  33. $admin = AdminService::getByCondition(['platUserId' => $userId]);
  34. if (empty($admin)) {
  35. util::fail('没有找到注册信息');
  36. }
  37. $merchantId = $admin['merchantId'];
  38. $merchant = MerchantService::getMerchantById($merchantId);
  39. util::success($merchant);
  40. }
  41. //商家信息 shish 2020.1.11
  42. public function actionDetail()
  43. {
  44. $id = Yii::$app->request->get('id');
  45. $merchant = MerchantService::getMerchantById(12358);
  46. util::success($merchant);
  47. }
  48. //开放平台设置相关操作 shish 2020.1.18
  49. public function actionBindOpen()
  50. {
  51. $isOpen = Yii::$app->request->get('isOpen', 1);
  52. $merchantId = 0;
  53. if ($isOpen == 0) {
  54. //其它
  55. $merchantId = Yii::$app->request->get('account', 0);
  56. $merchant = MerchantService::getById($merchantId);
  57. if (empty($merchant)) {
  58. util::fail('没有找到商家');
  59. }
  60. $wxAppId = $merchant['wxAppId'];
  61. $miniAppId = $merchant['miniAppId'];
  62. $openAppId = $merchant['openAppId'];
  63. } elseif ($isOpen == 1) {
  64. //零售
  65. $merchant = WxOpenClass::getWxInfo();
  66. $miniAppId = $merchant['miniAppId'];
  67. $wxAppId = $merchant['wxAppId'];
  68. $openAppId = $merchant['openAppId'];
  69. } elseif ($isOpen == 2) {
  70. //供货商
  71. $merchant = WxOpenClass::getGhsWxInfo();
  72. $miniAppId = $merchant['miniAppId'];
  73. $wxAppId = $merchant['wxAppId'];
  74. $openAppId = $merchant['openAppId'];
  75. }
  76. echo "<pre>";
  77. $id = Yii::$app->request->get('id', 0);
  78. //创建平台,并将公众号绑定到平台
  79. if ($id == 1) {
  80. wxUtil::createOpenAccount($wxAppId, $merchant, $isOpen);
  81. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  82. print_r($return);
  83. if ($return['errcode'] == 0) {
  84. $openAppId = $return['open_appid'];
  85. if ($isOpen == 0) {
  86. xhMerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
  87. MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppId' => $openAppId, 'openAppBind' => 1, 'wxAuth' => 1]);
  88. } elseif ($isOpen == 1) {
  89. $open = WxOpenClass::getOpen();
  90. $wxMiniBaseId = isset($open['wxMiniBaseId']) ? $open['wxMiniBaseId'] : 0;
  91. $wxBaseId = isset($open['wxBaseId']) ? $open['wxBaseId'] : 0;
  92. WxMiniBaseClass::updateById($wxMiniBaseId, ['openAppId' => $openAppId]);
  93. WxBaseClass::updateById($wxBaseId, ['openAppId' => $openAppId]);
  94. } elseif ($isOpen == 2) {
  95. $open = WxOpenClass::getOpen();
  96. $wxMiniBaseId = isset($open['wxGhsMiniBaseId']) ? $open['wxGhsMiniBaseId'] : 0;
  97. $wxBaseId = isset($open['wxGhsBaseId']) ? $open['wxGhsBaseId'] : 0;
  98. WxMiniBaseClass::updateById($wxMiniBaseId, ['openAppId' => $openAppId]);
  99. WxBaseClass::updateById($wxBaseId, ['openAppId' => $openAppId]);
  100. }
  101. }
  102. }
  103. //将小程序绑定到平台
  104. if ($id == 2) {
  105. $openAppId = $merchant['openAppId'];
  106. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true, $isOpen);
  107. //MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppBind' => 3, 'miniAuth' => 1]);
  108. print_r($r);
  109. }
  110. //查询公众号 小程序的绑定情况
  111. if ($id == 3) {
  112. Yii::info("查询公众号 小程序的绑定情况 wxAppId:{$wxAppId} isOpen:{$isOpen}");
  113. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  114. echo "公众号绑定情况:<br />";
  115. print_r($return);
  116. $return = wxUtil::getOpenAccount($miniAppId, $merchant, true, $isOpen);
  117. echo "小程序绑定情况:<br />";
  118. print_r($return);
  119. }
  120. //设置小程序服务器域名
  121. if ($id == 4) {
  122. wxUtil::setDomain($merchant, $isOpen);
  123. wxUtil::setWebViewDomain($merchant, $isOpen);
  124. }
  125. //为授权的小程序帐号上传小程序代码
  126. if ($id == 5) {
  127. //模板id
  128. $tId = Yii::$app->request->get('tId');
  129. wxUtil::miniCommit($merchant, $tId, $isOpen);
  130. }
  131. //获取小程序体验码
  132. if ($id == 6) {
  133. wxUtil::getExperienceQrCode($merchant, '', $isOpen);
  134. }
  135. //获取授权小程序帐号已设置的类目
  136. if ($id == 7) {
  137. wxUtil::getMiniCategory($merchant, $isOpen);
  138. }
  139. //获取小程序的第三方提交代码的页面配置
  140. if ($id == 8) {
  141. wxUtil::getMiniPage($merchant, $isOpen);
  142. }
  143. //将第三方提交的代码包提交审核
  144. if ($id == 9) {
  145. wxUtil::miniSubmitAudit($merchant, '', $isOpen);
  146. }
  147. //查询最新一次提交的审核状态
  148. if ($id == 10) {
  149. wxUtil::miniGetLatestAuditStatus($merchant, $isOpen);
  150. }
  151. //发布已通过审核的小程序
  152. if ($id == 11) {
  153. $respond = wxUtil::miniRelease($merchant, $isOpen);
  154. dd($respond);
  155. }
  156. //撤回审核
  157. if ($id == 12) {
  158. wxUtil::rollbackCheck($merchant, $isOpen);
  159. }
  160. //生成 申请会员页 的小程序码
  161. if ($id == 13) {
  162. wxUtil::generateMemberCode($merchant, $isOpen);
  163. }
  164. //解绑小程序和公众号绑定的平台
  165. if ($id == 14) {
  166. wxUtil::unbindAccount($merchant, $isOpen);
  167. wxUtil::unbindMiniProgram($merchant, $isOpen);
  168. }
  169. Yii::$app->end();
  170. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true, $isOpen);
  171. print_r($r);
  172. echo $miniAppId . ' ' . $openAppId . ' ';
  173. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  174. print_r($return);
  175. die;
  176. $return = wxUtil::createOpenAccount($wxAppId, $merchant, $isOpen);
  177. print_r($return);
  178. die;
  179. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, false, $isOpen);
  180. print_r($r);
  181. echo $miniAppId . ' ' . $openAppId . ' ';
  182. $return = wxUtil::getOpenAccount($wxAppId, $merchant, false, $isOpen);
  183. print_r($return);
  184. $return = wxUtil::getOpenAccount($miniAppId, $merchant, false, $isOpen);
  185. print_r($return);
  186. }
  187. //平台帐号激活 shish 2020.2.15
  188. public function actionAddPlatformMerchant()
  189. {
  190. MerchantService::initOpenMerchant();
  191. echo 'ok';
  192. }
  193. //注释商家 shish 2020.3.4
  194. public function actionCancel()
  195. {
  196. if (getenv('YII_ENV') != 'test') {
  197. util::fail('只有测试环境才能操作');
  198. }
  199. $id = Yii::$app->request->get('id', 0);
  200. $merchant = MerchantService::getById($id, true);
  201. if (isset($merchant->wxAppId) && empty($merchant->wxAppId)) {
  202. util::fail('已注销/未授权');
  203. }
  204. $merchant->wxAppId = '';
  205. $merchant->miniAppId = '';
  206. $merchant->save();
  207. $extend = MerchantExtendService::getByMerchantId($id, true);
  208. $extend->miniAppId = '';
  209. $extend->wxAppId = '';
  210. $extend->save();
  211. util::complete();
  212. }
  213. //商家h5商城二维码 shish 2020.4.30
  214. public function actionGetH5MallQrCode()
  215. {
  216. $id = Yii::$app->request->get('id', 0);
  217. $imgUrl = MerchantService::getH5MallQrCode($id);
  218. util::success(['imgUrl' => $imgUrl]);
  219. }
  220. }