NewSalesmanController.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\controllers;
  8. use app\models\AggregateQrcode;
  9. use app\models\MerchantInfo;
  10. use app\models\Store;
  11. use app\models\StoreAliMini;
  12. use app\models\StoreAudit;
  13. use app\models\StoreMini;
  14. use app\models\StoreSchedule;
  15. use app\modules\alliance\models\AlipayThirdForm;
  16. use app\modules\alliance\models\WechatThirdForm;
  17. use app\modules\alliance\controllers\BaseController;
  18. use app\modules\alliance\models\NewSalesmanForm;
  19. use app\utils\WechatMerchant\Merchant;
  20. use yii\helpers\Json;
  21. class NewSalesmanController extends BaseController
  22. {
  23. //TODO 商户逻辑 start
  24. //新增商户信息
  25. public function actionAddMerchant(){
  26. if(\Yii::$app->request->isPost){
  27. $form = new NewSalesmanForm();
  28. $form->contact_info = post_params("contact_info");
  29. $form->subject_info = post_params("subject_info");
  30. $form->business_info = post_params("business_info");
  31. $form->bank_account_info = post_params("bank_account_info");
  32. // $form->mini_apply_info = post_params("mini_apply_info");
  33. $form->bind_store_id = post_params("bind_store_id",136);
  34. $res = $form->saveMerchant();
  35. }else{
  36. $form = new NewSalesmanForm();
  37. $form->id = get_params('id');
  38. $res = $form->getMerchant();
  39. }
  40. return $this->asJson($res);
  41. }
  42. //快速注册小程序
  43. public function actionApplyMini(){
  44. $form = new NewSalesmanForm();
  45. $form->mini_apply_info = json_decode(post_params("mini_apply_info"));
  46. $form->bind_store_id = post_params("bind_store_id");
  47. $form->type = post_params("type",'weixin');
  48. $res = $form->applyMini();
  49. return $this->asJson($res);
  50. }
  51. //绑定小程序码
  52. public function actionBindPayQrcode(){
  53. $form = new NewSalesmanForm();
  54. $form->qrcode_id = post_params("qrcode_id");
  55. $form->type = post_params("type",'weixin');
  56. $form->bind_store_id = post_params("bind_store_id");
  57. $res = $form->bindPayQrcode();
  58. return $this->asJson($res);
  59. }
  60. //获取进度信息
  61. public function actionProgress(){
  62. $form = new NewSalesmanForm();
  63. $form->bind_store_id = post_params("bind_store_id");
  64. $form->type = post_params("type",'weixin');
  65. $res = $form->getProgress();
  66. return $this->asJson($res);
  67. }
  68. //查看个人中心信息
  69. public function actionGetUserInfo(){
  70. $form = new NewSalesmanForm();
  71. $res = $form->getUserInfo();
  72. return $this->asJson($res);
  73. }
  74. //查看店铺列表
  75. public function actionMchList(){
  76. $form = new NewSalesmanForm();
  77. $form->page = post_params("page");
  78. $form->status = post_params("status");
  79. $form->sort = post_params("sort");
  80. $form->category_id = post_params("category_id");
  81. $form->type = post_params("type",'weixin');
  82. $res = $form->merchantList();
  83. return $this->asJson($res);
  84. }//
  85. //查看店铺列表
  86. public function actionMchNewList(){
  87. $form = new NewSalesmanForm();
  88. $form->page = post_params("page");
  89. $form->status = post_params("status");
  90. $form->sort = post_params("sort");
  91. $form->category_id = post_params("category_id");
  92. $form->type = post_params("type",'weixin');
  93. $form->store_id = get_store_id();
  94. //当前接口由商城管理员打开 直接获取商城管理员的商城id
  95. try {
  96. $payload = \Yii::$app->jwt->getPayload();
  97. $store_admin_id = $payload['store_admin_id'];
  98. if ($store_admin_id > 0) {
  99. $StoreMiniAdmin = \app\models\StoreAdmin::findOne(['id' => $store_admin_id, 'status' => 1, 'is_delete' => 0]);
  100. $store_id = $StoreMiniAdmin->store_id;
  101. } else {
  102. $admin = \app\models\Admin::findOne(['id' => $payload['admin_id']]);
  103. $store_id = $admin->type_id;
  104. }
  105. $form->store_id = $store_id;
  106. } catch (\Exception $e) {
  107. return $this->asJson([
  108. 'code' => 1,
  109. 'msg' => '需要重新登录'
  110. ]);
  111. }
  112. $res = $form->merchantNewList();
  113. return $this->asJson($res);
  114. }
  115. //
  116. public function actionAudit(){
  117. $form = new NewSalesmanForm();
  118. $form->id = post_params("id");
  119. $form->status = post_params("status");
  120. $form->business_model = post_params("business_model");
  121. $form->qrcode_id = post_params("qrcode_id");
  122. $res = $form->audit();
  123. return $this->asJson($res);
  124. }
  125. //
  126. public function actionGetQrcode(){
  127. $form = new NewSalesmanForm();
  128. $form->business_model = post_params("business_model");
  129. $res = $form->getQrcode();
  130. return $this->asJson($res);
  131. }
  132. //获取进件资料信息
  133. public function actionGetApplyInfo(){
  134. $form = new NewSalesmanForm();
  135. $form->bind_store_id = post_params("bind_store_id");
  136. $res = $form->getInfo();
  137. return $this->asJson($res);
  138. }
  139. ///
  140. /// 微信小程序
  141. ///
  142. //修改信息
  143. public function actionEditMiniInfo(){
  144. $form = new WechatThirdForm();
  145. $form->bind_store_id = post_params("bind_store_id");
  146. $form->mini_nickname = post_params("mini_nickname");
  147. $form->head_img_media_id = post_params("mini_url");
  148. $form->signature = post_params("signature");
  149. $res = $form->setHeadImage();
  150. if($res['code'] === 0){
  151. $res = $form->setSignature();
  152. if($res['code'] === 0){
  153. $res = $form->setMiniNianname();
  154. return $this->asJson($res);
  155. }
  156. }
  157. return $this->asJson($res);
  158. }
  159. //获取分类
  160. public function actionGetAllCategory(){
  161. $form = new WechatThirdForm();
  162. $form->bind_store_id = post_params("bind_store_id");
  163. $res = $form->getAllCategories();
  164. return $this->asJson($res);
  165. }
  166. //获取已经设置的分类
  167. public function actionGetCategory(){
  168. $form = new WechatThirdForm();
  169. $form->bind_store_id = post_params("bind_store_id");
  170. $res = $form->getCategories();
  171. return $this->asJson($res);
  172. }
  173. //修改分类
  174. public function actionSetCategory(){
  175. $form = new WechatThirdForm();
  176. $form->bind_store_id = post_params("bind_store_id");
  177. $form->categories = post_params("categories");
  178. $res = $form->addCategory();
  179. return $this->asJson($res);
  180. }
  181. //删除分类
  182. public function actionDelCategory(){
  183. $form = new WechatThirdForm();
  184. $form->bind_store_id = post_params("bind_store_id");
  185. $form->cate_first = post_params("cate_first");
  186. $form->cate_second = post_params("cate_second");
  187. $res = $form->delCategory();
  188. return $this->asJson($res);
  189. }
  190. //上传小程序
  191. public function actionUpMini(){
  192. $form = new WechatThirdForm();
  193. $form->bind_store_id = post_params("bind_store_id");
  194. $res = $form->upMini();
  195. return $this->asJson($res);
  196. }
  197. //审核小程序
  198. public function actionSubmitAudit(){
  199. $form = new WechatThirdForm();
  200. $form->bind_store_id = post_params("bind_store_id");
  201. $res = $form->submitAudit();
  202. return $this->asJson($res);
  203. }
  204. //审核撤回
  205. public function actionCancelSubmitAudit(){
  206. $form = new WechatThirdForm();
  207. $form->bind_store_id = post_params("bind_store_id");
  208. $res = $form->unDoCodeAudit();
  209. return $this->asJson($res);
  210. }
  211. //发布已经通过审核的小程序
  212. public function actionRelease(){
  213. $form = new WechatThirdForm();
  214. $form->bind_store_id = post_params("bind_store_id");
  215. $res = $form->release();
  216. return $this->asJson($res);
  217. }
  218. ///
  219. /// 支付宝小程序
  220. ///
  221. //获取支付宝进度
  222. public function actionAliProgress(){
  223. $form = new NewSalesmanForm();
  224. $form->bind_store_id = post_params("bind_store_id");
  225. $res = $form->getProgress();
  226. return $this->asJson($res);
  227. }
  228. //修改资料
  229. public function actionSetInfo(){
  230. $form = new AlipayThirdForm();
  231. $form->AppName = post_params("app_name");
  232. $form->AppEnglishName = post_params("app_english_name");
  233. $form->AppSlogan = post_params("app_slogan");
  234. $form->AppLogo = post_params("app_logo");
  235. $form->AppDesc = post_params("app_desc");
  236. $form->ServicePhone = post_params("service_phone");
  237. $form->ServiceEmail = post_params("service_email");
  238. $form->MiniCategoryIds = post_params("mini_categoryIds");
  239. $form->bind_store_id = post_params("bind_store_id");
  240. $res = $form->setMiniBaseInfo();
  241. return $this->asJson($res);
  242. }
  243. //上传代码
  244. public function actionUpAliMini(){
  245. $form = new AlipayThirdForm();
  246. $form->bind_store_id = post_params("bind_store_id");
  247. $res = $form->updateMiniVersion();
  248. return $this->asJson($res);
  249. }
  250. //签约流程
  251. public function actionSignContract(){
  252. $form = new AlipayThirdForm();
  253. $form->bind_store_id = post_params("bind_store_id");
  254. $res = $form->agentCreate();
  255. return $this->asJson($res);
  256. }
  257. //审核小程序
  258. public function actionAuditAliMini(){
  259. $form = new AlipayThirdForm();
  260. $form->bind_store_id = post_params("bind_store_id");
  261. $aliMini = StoreAliMini::find()->where(['store_id'=>post_params("bind_store_id")])->orderBy('id desc')->select('license_no,license_pic,app_name,app_english_name,app_slogan,app_logo,app_desc,service_phone,service_email,mini_categoryIds,license_name,license_date,is_long_effective')->one();
  262. $audit = [
  263. "AppName"=>$aliMini->app_name,
  264. "AppEnglishName"=>$aliMini->app_english_name,
  265. "AppSlogan"=>$aliMini->app_slogan,
  266. "AppLogo"=>$aliMini->app_logo,
  267. "AppDesc"=>$aliMini->app_desc,
  268. "ServicePhone"=>$aliMini->service_phone,
  269. "ServiceEmail"=>$aliMini->service_email,
  270. "MiniCategoryIds"=>$aliMini->mini_categoryIds,
  271. "license_no"=>$aliMini->license_no,
  272. "license_pic"=>$aliMini->license_pic,
  273. "license_name"=>$aliMini->license_name,
  274. "license_date"=>$aliMini->license_date,
  275. "is_long_effective"=>$aliMini->is_long_effective,
  276. ];
  277. $form->auditData = $audit;
  278. $res = $form->miniAuditApply();
  279. return $this->asJson($res);
  280. }
  281. //发布小程序
  282. public function actionPushMini(){
  283. $form = new AlipayThirdForm();
  284. $form->bind_store_id = post_params("bind_store_id");
  285. $res = $form->miniOnline();
  286. return $this->asJson($res);
  287. }
  288. //进件
  289. public function actionApply() {
  290. $StoreSchedule = StoreSchedule::find()->where(['store_id'=>post_params("bind_store_id")])->select('merchant_info,audit_id')->one();
  291. if(!empty($StoreSchedule->audit_id)){
  292. $StoreAudit = StoreAudit::find()->where(['id'=>$StoreSchedule->audit_id])->select('merchant_info_id')->one();
  293. }
  294. $appid = "";
  295. $store = Store::findOne(post_params("bind_store_id"));
  296. if ($store->business_model === 1) {
  297. $StoreMini = StoreMini::find()->where(['store_id'=>post_params("bind_store_id")])->select('appid')->orderBy('id desc')->one();
  298. if(!empty($StoreMini->appid)){
  299. $appid = $StoreMini->appid;
  300. }
  301. } else {
  302. $appid = "";
  303. }
  304. $merchant_info = json_decode(post_params("merchant_info"),true);
  305. if(empty(post_params("merchant_info"))){
  306. if(!empty($StoreSchedule->merchant_info)){
  307. $merchant_info = json_decode($StoreSchedule->merchant_info,true);
  308. }
  309. }
  310. $contact_info = $merchant_info['contact_info'];
  311. $subject_info = $merchant_info['subject_info'];
  312. $business_info = $merchant_info['business_info'];
  313. $bank_account_info = $merchant_info['bank_account_info'];
  314. $apply_id = !empty($StoreAudit->merchant_info_id)?$StoreAudit->merchant_info_id:0;
  315. try {
  316. $merchant = new Merchant();
  317. } catch (\Exception $e) {
  318. return $this->asJson([
  319. 'code' => 1,
  320. 'msg' => $e->getMessage()
  321. ]);
  322. }
  323. return $this->asJson($merchant->submit($contact_info, $subject_info, $business_info, $bank_account_info, $apply_id, $appid));
  324. }
  325. }