MerchantController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace saas\controllers;
  3. use Yii;
  4. use biz\admin\services\AdminService;
  5. use biz\merchant\services\MerchantService;
  6. use common\components\util;
  7. use common\components\wxUtil;
  8. use common\services\xhMerchantService;
  9. class MerchantController extends BaseController
  10. {
  11. public $withoutLogin = ['bind-open'];
  12. //商家列表 shish 2019.12.20
  13. public function actionList()
  14. {
  15. $where = [];
  16. $list = MerchantService::getSaasMerchant($where);
  17. util::success($list);
  18. }
  19. //获取当前登陆老板的帐号详情,官网购买套餐时使用 shish 2020.1.11
  20. public function actionLoginAccount()
  21. {
  22. $userId = $this->userId;
  23. $admin = AdminService::getByCondition(['platUserId' => $userId]);
  24. if (empty($admin)) {
  25. util::fail('没有找到注册信息');
  26. }
  27. $merchantId = $admin['merchantId'];
  28. $merchant = MerchantService::getMerchantById($merchantId);
  29. util::success($merchant);
  30. }
  31. //商家信息 shish 2020.1.11
  32. public function actionDetail()
  33. {
  34. $id = Yii::$app->request->get('id');
  35. $merchant = MerchantService::getMerchantById(12358);
  36. util::success($merchant);
  37. }
  38. public function actionBindOpen()
  39. {
  40. $merchantId = Yii::$app->request->get('account', 0);
  41. $merchant = MerchantService::getById($merchantId);
  42. if (empty($merchant)) {
  43. util::fail('没有找到商家');
  44. }
  45. $wxAppId = $merchant['wxAppId'];
  46. $miniAppId = $merchant['miniAppId'];
  47. $openAppId = $merchant['openAppId'];
  48. echo "<pre>";
  49. $id = Yii::$app->request->get('id', 0);
  50. //创建平台,并将公众号绑定到平台
  51. if ($id == 1) {
  52. wxUtil::createOpenAccount($wxAppId, $merchant);
  53. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  54. print_r($return);
  55. if ($return['errcode'] == 0) {
  56. $openAppId = $return['open_appid'];
  57. xhMerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
  58. }
  59. }
  60. //将小程序绑定到平台
  61. if ($id == 2) {
  62. $openAppId = $merchant['openAppId'];
  63. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
  64. print_r($r);
  65. }
  66. //查询公众号 小程序的绑定情况
  67. if ($id == 3) {
  68. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  69. echo "公众号绑定情况:<br />";
  70. print_r($return);
  71. $return = wxUtil::getOpenAccount($miniAppId, $merchant, true);
  72. echo "小程序绑定情况:<br />";
  73. print_r($return);
  74. }
  75. //设置小程序服务器域名
  76. if ($id == 4) {
  77. wxUtil::setDomain($merchant);
  78. wxUtil::setWebViewDomain($merchant);
  79. }
  80. //为授权的小程序帐号上传小程序代码
  81. if ($id == 5) {
  82. //模板id
  83. $tId = Yii::$app->request->get('tId');
  84. wxUtil::miniCommit($merchant, $tId);
  85. }
  86. //获取小程序体验码
  87. if ($id == 6) {
  88. wxUtil::getExperienceQrCode($merchant);
  89. }
  90. //获取授权小程序帐号已设置的类目
  91. if ($id == 7) {
  92. wxUtil::getMiniCategory($merchant);
  93. }
  94. //获取小程序的第三方提交代码的页面配置
  95. if ($id == 8) {
  96. wxUtil::getMiniPage($merchant);
  97. }
  98. //将第三方提交的代码包提交审核
  99. if ($id == 9) {
  100. wxUtil::miniSubmitAudit($merchant);
  101. }
  102. //查询最新一次提交的审核状态
  103. if ($id == 10) {
  104. wxUtil::miniGetLatestAuditStatus($merchant);
  105. }
  106. //发布已通过审核的小程序
  107. if ($id == 11) {
  108. wxUtil::miniRelease($merchant);
  109. }
  110. //撤回审核
  111. if ($id == 12) {
  112. wxUtil::rollbackCheck($merchant);
  113. }
  114. //生成 申请会员页 的小程序码
  115. if ($id == 13) {
  116. wxUtil::generateMemberCode($merchant);
  117. }
  118. //解绑小程序和公众号绑定的平台
  119. if ($id == 14) {
  120. wxUtil::unbindAccount($merchant);
  121. wxUtil::unbindMiniProgram($merchant);
  122. }
  123. Yii::$app->end();
  124. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
  125. print_r($r);
  126. echo $miniAppId . ' ' . $openAppId . ' ';
  127. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  128. print_r($return);
  129. die;
  130. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  131. print_r($return);
  132. die;
  133. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant);
  134. print_r($r);
  135. echo $miniAppId . ' ' . $openAppId . ' ';
  136. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  137. print_r($return);
  138. $return = wxUtil::getOpenAccount($miniAppId, $merchant);
  139. print_r($return);
  140. die;
  141. if ($return['errcode'] == 0) {
  142. $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
  143. } else {
  144. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  145. if ($return['errcode'] == 0) {
  146. $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
  147. }
  148. }
  149. echo "<br />openAppId:" . $openAppId . "<br />";
  150. if (!empty($openAppId)) {
  151. xhMerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
  152. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant);
  153. echo "绑定小程序结果:<br />";
  154. print_r($r);
  155. }
  156. echo "<br /><br />";
  157. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  158. echo "微信appId:{$wxAppId}<br />";
  159. print_r($return);
  160. $return = wxUtil::getOpenAccount($miniAppId, $merchant);
  161. echo "<br />小程序appId:{$miniAppId}<br />";
  162. print_r($return);
  163. }
  164. }