MerchantController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. $tId = $_GET['tId'];
  83. wxUtil::miniCommit($merchant, $tId);
  84. }
  85. //获取小程序体验码
  86. if ($id == 6) {
  87. wxUtil::getExperienceQrCode($merchant);
  88. }
  89. //获取授权小程序帐号已设置的类目
  90. if ($id == 7) {
  91. wxUtil::getMiniCategory($merchant);
  92. }
  93. //获取小程序的第三方提交代码的页面配置
  94. if ($id == 8) {
  95. wxUtil::getMiniPage($merchant);
  96. }
  97. //将第三方提交的代码包提交审核
  98. if ($id == 9) {
  99. wxUtil::miniSubmitAudit($merchant);
  100. }
  101. //查询最新一次提交的审核状态
  102. if ($id == 10) {
  103. wxUtil::miniGetLatestAuditStatus($merchant);
  104. }
  105. //发布已通过审核的小程序
  106. if ($id == 11) {
  107. wxUtil::miniRelease($merchant);
  108. }
  109. //撤回审核
  110. if ($id == 12) {
  111. wxUtil::rollbackCheck($merchant);
  112. }
  113. //生成 申请会员页 的小程序码
  114. if ($id == 13) {
  115. wxUtil::generateMemberCode($merchant);
  116. }
  117. //解绑小程序和公众号绑定的平台
  118. if ($id == 14) {
  119. wxUtil::unbindAccount($merchant);
  120. wxUtil::unbindMiniProgram($merchant);
  121. }
  122. Yii::$app->end();
  123. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
  124. print_r($r);
  125. echo $miniAppId . ' ' . $openAppId . ' ';
  126. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  127. print_r($return);
  128. die;
  129. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  130. print_r($return);
  131. die;
  132. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant);
  133. print_r($r);
  134. echo $miniAppId . ' ' . $openAppId . ' ';
  135. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  136. print_r($return);
  137. $return = wxUtil::getOpenAccount($miniAppId, $merchant);
  138. print_r($return);
  139. die;
  140. if ($return['errcode'] == 0) {
  141. $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
  142. } else {
  143. $return = wxUtil::createOpenAccount($wxAppId, $merchant);
  144. if ($return['errcode'] == 0) {
  145. $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
  146. }
  147. }
  148. echo "<br />openAppId:" . $openAppId . "<br />";
  149. if (!empty($openAppId)) {
  150. xhMerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
  151. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant);
  152. echo "绑定小程序结果:<br />";
  153. print_r($r);
  154. }
  155. echo "<br /><br />";
  156. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  157. echo "微信appId:{$wxAppId}<br />";
  158. print_r($return);
  159. $return = wxUtil::getOpenAccount($miniAppId, $merchant);
  160. echo "<br />小程序appId:{$miniAppId}<br />";
  161. print_r($return);
  162. }
  163. }