MerchantController.php 8.5 KB

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