MerchantController.php 5.1 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. $account = Yii::$app->request->get('account', 0);
  41. $merchant = MerchantService::getById($account);
  42. if (empty($merchant)) {
  43. util::fail('没有找到商家');
  44. }
  45. wxUtil::miniCommit($merchant,1);die;
  46. $wxAppId = $merchant['wxAppId'];
  47. $miniAppId = $merchant['miniAppId'];
  48. $openAppId = $merchant['openAppId'];
  49. echo "<pre>";
  50. $id = Yii::$app->request->get('id', 0);
  51. //创建平台,并将公众号绑定到平台
  52. if ($id == 1) {
  53. wxUtil::createOpenAccount($wxAppId, $this->merchant);
  54. $return = wxUtil::getOpenAccount($wxAppId, $this->merchant);
  55. print_r($return);
  56. if ($return['errcode'] == 0) {
  57. $openAppId = $return['open_appid'];
  58. xhMerchantService::updateById($this->merchantId, ['openAppId' => $openAppId]);
  59. }
  60. }
  61. //将小程序绑定到平台
  62. if ($id == 2) {
  63. $openAppId = $merchant['openAppId'];
  64. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
  65. print_r($r);
  66. }
  67. //查询公众号 小程序的绑定情况
  68. if ($id == 3) {
  69. $return = wxUtil::getOpenAccount($wxAppId, $this->merchant);
  70. print_r($return);
  71. $return = wxUtil::getOpenAccount($miniAppId, $this->merchant, true);
  72. print_r($return);
  73. }
  74. //设置小程序服务器域名
  75. if ($id == 4) {
  76. wxUtil::setDomain($this->merchant);
  77. wxUtil::setWebViewDomain($this->merchant);
  78. }
  79. //为授权的小程序帐号上传小程序代码
  80. if ($id == 5) {
  81. $tId = $_GET['tId'];
  82. wxUtil::miniCommit($this->merchant, $tId);
  83. }
  84. //获取小程序体验码
  85. if ($id == 6) {
  86. wxUtil::getExperienceQrCode($this->merchant);
  87. }
  88. //获取授权小程序帐号已设置的类目
  89. if ($id == 7) {
  90. wxUtil::getMiniCategory($this->merchant);
  91. }
  92. //获取小程序的第三方提交代码的页面配置
  93. if ($id == 8) {
  94. wxUtil::getMiniPage($this->merchant);
  95. }
  96. //将第三方提交的代码包提交审核
  97. if ($id == 9) {
  98. wxUtil::miniSubmitAudit($this->merchant);
  99. }
  100. //查询最新一次提交的审核状态
  101. if ($id == 10) {
  102. wxUtil::miniGetLatestAuditStatus($this->merchant);
  103. }
  104. //发布已通过审核的小程序
  105. if ($id == 11) {
  106. wxUtil::miniRelease($this->merchant);
  107. }
  108. //撤回审核
  109. if ($id == 12) {
  110. wxUtil::rollbackCheck($this->merchant);
  111. }
  112. //生成 申请会员页 的小程序码
  113. if ($id == 13) {
  114. wxUtil::generateMemberCode($this->merchant);
  115. }
  116. //解绑小程序和公众号绑定的平台
  117. if ($id == 14) {
  118. wxUtil::unbindAccount($this->merchant);
  119. wxUtil::unbindMiniProgram($this->merchant);
  120. }
  121. Yii::$app->end();
  122. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant, true);
  123. print_r($r);
  124. echo $miniAppId . ' ' . $openAppId . ' ';
  125. $return = wxUtil::getOpenAccount($wxAppId, $this->merchant);
  126. print_r($return);
  127. die;
  128. $return = wxUtil::createOpenAccount($wxAppId, $this->merchant);
  129. print_r($return);
  130. die;
  131. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant);
  132. print_r($r);
  133. echo $miniAppId . ' ' . $openAppId . ' ';
  134. $return = wxUtil::getOpenAccount($wxAppId, $this->merchant);
  135. print_r($return);
  136. $return = wxUtil::getOpenAccount($miniAppId, $this->merchant);
  137. print_r($return);
  138. die;
  139. if ($return['errcode'] == 0) {
  140. $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
  141. } else {
  142. $return = wxUtil::createOpenAccount($wxAppId, $this->merchant);
  143. if ($return['errcode'] == 0) {
  144. $openAppId = isset($return['open_appid']) ? $return['open_appid'] : '';
  145. }
  146. }
  147. echo "<br />openAppId:" . $openAppId . "<br />";
  148. if (!empty($openAppId)) {
  149. xhMerchantService::updateById($this->merchantId, ['openAppId' => $openAppId]);
  150. $r = wxUtil::bindOpenAccount($miniAppId, $openAppId, $merchant);
  151. echo "绑定小程序结果:<br />";
  152. print_r($r);
  153. }
  154. echo "<br /><br />";
  155. $return = wxUtil::getOpenAccount($wxAppId, $merchant);
  156. echo "微信appId:{$wxAppId}<br />";
  157. print_r($return);
  158. $return = wxUtil::getOpenAccount($miniAppId, $merchant);
  159. echo "<br />小程序appId:{$miniAppId}<br />";
  160. print_r($return);
  161. }
  162. }