MerchantController.php 5.8 KB

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