MerchantController.php 5.0 KB

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