ProgressMiniForm.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\models\third\ali;
  8. use app\models\AggregateQrcode;
  9. use app\models\MerchantInfo;
  10. use app\models\Store;
  11. use app\models\StoreAliMini;
  12. use app\models\StoreAliMiniVersion;
  13. use app\models\StoreMiniToken;
  14. use app\models\StoreSchedule;
  15. class ProgressMiniForm extends BaseForm
  16. {
  17. public function inits()
  18. {
  19. try {
  20. $store_id = $this->store_id;
  21. if (!empty($store_id)) {
  22. $store_mini = StoreAliMini::find()->where(['store_id' => $store_id])->orderBy('id desc')->one();
  23. if (!empty($store_mini->id)) {
  24. $this->mini_id = $store_mini->id;
  25. }
  26. $this->store_mini = $store_mini;
  27. $this->mini_version = StoreAliMiniVersion::find()->where(['mini_id' => $store_mini->id])->orderBy('id desc')->one();
  28. }
  29. //获取二维码信息
  30. $qrcode_id = $this->qrcode_id;
  31. if (!empty($qrcode_id)) {
  32. $qrcode = AggregateQrcode::findOne($qrcode_id);
  33. if (empty($qrcode)) {
  34. return [
  35. 'code' => 1,
  36. 'msg' => "二维码不存在"
  37. ];
  38. }
  39. if ($qrcode->ali_status == 1) {
  40. return [
  41. 'code' => 1,
  42. 'msg' => "二维码已经被使用"
  43. ];
  44. }
  45. $this->qrcode = $qrcode;
  46. }
  47. } catch (\Exception $e) {
  48. return [
  49. 'code' => 1,
  50. 'msg' => $e->getMessage()
  51. ];
  52. }
  53. }
  54. public function registerMiniStatus()
  55. {
  56. try {
  57. $result = $this->inits();
  58. if ($result['code'] === 1) {
  59. return $result;
  60. }
  61. /**
  62. * 小程序注册
  63. * status = 0 没有注册小程序信息
  64. * status = 1 小程序注册待确认或签约审核中
  65. * status = 2 小程序注册已拒绝
  66. */
  67. //商城ID
  68. $store_id = $this->store_id;
  69. //小程序ID
  70. $mini_id = $this->mini_id;
  71. //小程序Model
  72. $store_mini = $this->store_mini;
  73. //小程序版本信息
  74. $mini_version = $this->mini_version;
  75. //获取店铺信息
  76. $store = Store::findOne($store_id);
  77. //申请店铺进件信息
  78. // $store_schedule = StoreSchedule::find()->where(['store_id' => $store_id])->asArray()->one();
  79. // //获取注册信息
  80. // $merchant_info = json_decode($store_schedule['merchant_info'], true);
  81. // //获取营业执照信息
  82. // $license_info = $merchant_info['subject_info']['business_license_info'];
  83. //注册小程序信息
  84. $data = [
  85. "license_name" => $store_mini->license_name ?: '',
  86. "license_no" => $store_mini->license_no ?: '',
  87. "app_name" => $store_mini->app_name ?: $store->name,
  88. "service_phone" => $store_mini->service_phone,
  89. "license_pic" => $store_mini->license_pic ?: '',
  90. "alipay_account" => $store_mini->alipay_account,
  91. "legal_personal_name" => $store_mini->legal_personal_name ?: '',
  92. "contact_name" => $store_mini->legal_personal_name ?: ''
  93. ];
  94. if (empty($store_mini->license_no) || ((int)$store_mini->order_cancel === 1)) {
  95. $token_log = StoreMiniToken::findOne(['store_id' => $store_id]);
  96. if (((int)$store_mini->is_merchant === 1) || ($token_log->id && ((int)$token_log->status === 1))) {
  97. return [
  98. 'code'=>0,
  99. 'msg'=>"需要注册小程序信息",
  100. 'data'=>[
  101. 'status' => 0,
  102. 'mini_info' => $data,
  103. 'bind_store_id' => $store_id,
  104. 'progress' => 0,
  105. 'business_model' => $store->business_model
  106. ],
  107. ];
  108. } elseif ($token_log->id && (int)$token_log->status === 0) {
  109. return [
  110. 'code'=>0,
  111. 'msg'=>"正在认证",
  112. 'data'=>[
  113. 'status' => -1,
  114. 'mini_info' => $data,
  115. 'bind_store_id' => $store_id,
  116. 'progress' => 0,
  117. 'business_model' => $store->business_model
  118. ],
  119. ];
  120. } elseif ((empty($store_mini->is_merchant)) && (empty($token_log->id) || (int)$token_log->status === 2)) {
  121. return [
  122. 'code'=>0,
  123. 'msg'=>"需要认证",
  124. 'data'=>[
  125. 'status' => -2,
  126. 'mini_info' => $data,
  127. 'bind_store_id' => $store_id,
  128. 'progress' => 0,
  129. 'business_model' => $store->business_model
  130. ],
  131. ];
  132. }
  133. }
  134. $form = new RegisterMiniForm();
  135. $form->mini_id = $mini_id;
  136. if (empty($store_mini->auth_app_id) && !empty($store_mini->order_no)) {
  137. $result = $form->getFastRegisterStatus();
  138. if ($result['code'] != 0) {
  139. throw new \Exception($result['msg']);
  140. }
  141. return [
  142. 'code'=>0,
  143. 'msg'=>"小程序注册待确认或签约审核中",
  144. 'data'=>[
  145. 'status' => 1,
  146. 'mini_info' => $data,
  147. 'bind_store_id' => $store_id,
  148. 'mini_id' => $mini_id,
  149. 'progress' => 0,
  150. 'business_model' => $store->business_model
  151. ],
  152. ];
  153. }
  154. if ($store_mini->order_cancel == 1) {
  155. return [
  156. 'code'=>0,
  157. 'msg'=>"小程序注册已拒绝",
  158. 'data'=>[
  159. 'status' => 2,
  160. 'mini_info' => $data,
  161. 'bind_store_id' => $store_id,
  162. 'mini_id' => $mini_id,
  163. 'progress' => 0,
  164. 'business_model' => $store->business_model
  165. ]
  166. ];
  167. }
  168. if ($store_mini->auth_app_id) {
  169. $result = $form->getAesKey();
  170. if ($result['code'] != 0) {
  171. throw new \Exception($result['msg']);
  172. }
  173. }
  174. return $this->perfectMiniStatus();
  175. } catch (\Exception $e) {
  176. return [
  177. 'code' => 0,
  178. 'msg' => $e->getMessage(),
  179. 'data'=>[
  180. 'status' => 1,
  181. 'progress' => 0,
  182. 'business_model' => $store->business_model
  183. ]
  184. ];
  185. }
  186. }
  187. /**
  188. * 完善信息
  189. */
  190. public function perfectMiniStatus()
  191. {
  192. try {
  193. /**
  194. * 小程序完善信息
  195. * status = 0 小程序资料需要完善
  196. */
  197. //商城ID
  198. $store_id = $this->store_id;
  199. //小程序ID
  200. $mini_id = $this->mini_id;
  201. //小程序Model
  202. $store_mini = $this->store_mini;
  203. //小程序版本信息
  204. $mini_version = $this->mini_version;
  205. $store = Store::findOne($store_id);
  206. //配置前端展示数据
  207. $form = new PerfectMiniForm();
  208. // $all_categories = $form->getAllCategory();
  209. // $all_category = [];
  210. // $old_category = [];
  211. // if ($all_categories['code'] === 0) {
  212. // $all_category = $all_categories['data'];
  213. // $old_category = $all_categories['old_data'];
  214. // }
  215. $form->mini_id = $mini_id;
  216. $data = [
  217. "app_name" => $store_mini['app_name'] ?: $store->name,
  218. "app_english_name" => $store_mini['app_english_name'],
  219. "app_slogan" => $store_mini['app_slogan'],
  220. "license_no" => $store_mini['license_no'],
  221. "license_pic" => $store_mini['license_pic'],
  222. "license_name" => $store_mini['license_name'],
  223. "license_date" => $store_mini['license_date'],
  224. "is_long_effective" => $store_mini['is_long_effective'],
  225. "app_logo" => $store_mini['app_logo'] ?: $store->logo,
  226. "app_desc" => $store_mini['app_desc'],
  227. "service_phone" => $store_mini['service_phone'],
  228. "service_email" => $store_mini['service_email'],
  229. 'other_data' => json_decode($store_mini['other_data']) ?: []
  230. ];
  231. if ($mini_version->is_submit == 0 && (
  232. empty($store_mini['app_name']) ||
  233. empty($store_mini['app_english_name']) ||
  234. empty($store_mini['app_slogan']) ||
  235. empty($store_mini['app_logo']) ||
  236. empty($store_mini['app_desc']) ||
  237. empty($store_mini['service_phone']) ||
  238. empty($store_mini['service_email'])
  239. )) {
  240. return [
  241. 'code'=>0,
  242. 'msg'=>"小程序资料需要完善",
  243. 'data'=>[
  244. 'status' => 0,
  245. 'mini_info' => $data,
  246. 'bind_store_id' => $store_id,
  247. 'mini_id' => $mini_id,
  248. 'progress' => 1,
  249. 'business_model' => $store->business_model
  250. ]
  251. ];
  252. }
  253. return $this->submitMiniStatus($data);
  254. } catch (\Exception $e) {
  255. return [
  256. 'code' => 0,
  257. 'msg' => $e->getMessage(),
  258. 'data' => [
  259. 'progress' => 1,
  260. 'status' => 1
  261. ]
  262. ];
  263. }
  264. }
  265. public function submitMiniStatus($data = [])
  266. {
  267. try {
  268. /**
  269. * 小程序提交审核资料、发布
  270. * status = 0 小程序待审核
  271. * status = 1 小程序审核中
  272. * status = 2 小程序审核失败
  273. * status = 3 小程序待发布
  274. */
  275. //小程序版本信息
  276. $mini_version = $this->mini_version;
  277. $store_id = $this->store_id;
  278. //获取店铺信息
  279. $store = Store::findOne($store_id);
  280. $mini_id = $this->mini_id;
  281. $form = new SubmitMiniForm();
  282. $form->mini_id = $mini_id;
  283. if ($mini_version->is_submit == 0 && $mini_version->is_back == 0 && $mini_version->create_time < strtotime(date("Y-m-d"))) {
  284. return [
  285. 'code' => 0,
  286. 'msg' => "小程序更新模板",//可以审核
  287. 'data' => [
  288. 'status' => 3,
  289. 'mini_info' => $data,
  290. 'bind_store_id' => $store_id,
  291. 'mini_id' => $mini_id,
  292. 'progress' => 2,
  293. 'business_model' => $store->business_model
  294. ]
  295. ];
  296. }
  297. if($mini_version->is_submit == 0) {
  298. return [
  299. 'code' => 0,
  300. 'msg' => $mini_version->is_back == 0 ? "小程序待审核" : $mini_version->fail_reason,//可以审核
  301. 'data' => [
  302. 'status' => 0,
  303. 'mini_info' => $data,
  304. 'bind_store_id' => $store_id,
  305. 'mini_id' => $mini_id,
  306. 'progress' => 2,
  307. 'business_model' => $store->business_model
  308. ]
  309. ];
  310. }
  311. if ($mini_version->is_submit == 1) {
  312. return [
  313. 'code'=>0,
  314. 'msg'=>"小程序审核中",
  315. 'data'=>[
  316. 'status'=>1,
  317. 'mini_info'=>$data,
  318. 'bind_store_id' => $store_id,
  319. 'mini_id' => $mini_id,
  320. 'progress' => 2,
  321. 'business_model' => $store->business_model
  322. ]
  323. ];
  324. }
  325. if ($mini_version->is_submit == 3) {
  326. $result = $form->backPerfect();
  327. if ($result != 0) {
  328. throw new \Exception($result['msg']);
  329. }
  330. return [
  331. 'code'=>0,
  332. 'msg'=>"小程序审核失败",
  333. 'data'=>[
  334. 'status' => 3,
  335. 'mini_info' => $data,
  336. 'bind_store_id' => $store_id,
  337. 'mini_id' => $mini_id,
  338. 'progress' => 2,
  339. 'business_model' => $store->business_model
  340. ]
  341. ];
  342. }
  343. if ($mini_version->is_submit == 2) {
  344. return [
  345. 'code'=>0,
  346. 'msg'=>"小程序待发布",//可以发布
  347. 'data'=>[
  348. 'status' => 2,
  349. 'mini_info' => $data,
  350. 'bind_store_id' => $store_id,
  351. 'mini_id' => $mini_id,
  352. 'progress' => 2,
  353. 'business_model' => $store->business_model
  354. ]
  355. ];
  356. }
  357. return $this->faceMiniStatus();
  358. } catch (\Exception $e) {
  359. return [
  360. 'code' => 0,
  361. 'msg' => $e->getMessage(),
  362. 'data' => [
  363. 'progress' => 2,
  364. 'status' => 3
  365. ]
  366. ];
  367. }
  368. }
  369. //签约当面付
  370. public function faceMiniStatus()
  371. {
  372. try {
  373. /**
  374. * 签约当面付
  375. * status = 0 需要创建事务
  376. * status = 1 需要签约当面付
  377. * status = 2 审核当面付
  378. * status = 3 审核中
  379. * status = 4 等待商户确认
  380. * status = 5 审核失败
  381. */
  382. //商城ID
  383. $store_id = $this->store_id;
  384. $store = Store::findOne($store_id);
  385. //小程序ID
  386. $mini_id = $this->mini_id;
  387. //小程序Model
  388. $store_mini = $this->store_mini;
  389. //小程序版本信息
  390. $mini_version = $this->mini_version;
  391. $form = new FaceMiniForm();
  392. $form->mini_id = $mini_id;
  393. if (!empty($store_mini->batch_no) && $store_mini->batch_status != 6) {
  394. $result = $form->openAgentOrderStatus();
  395. if ($result['code'] != 0) {
  396. throw new \Exception($result['msg']);
  397. }
  398. $result = $result['data'];
  399. }
  400. if ($store_mini->batch_status == 0 || $store_mini->batch_status == 7 || empty($store_mini->batch_no)) {//没有创建事务
  401. return [
  402. 'code'=>0,
  403. 'msg'=>"需要创建事务",
  404. 'data'=>[
  405. 'status' => 0,
  406. 'bind_store_id' => $store_id,
  407. 'mini_id' => $mini_id,
  408. 'progress' => 3,
  409. 'business_model' => $store->business_model
  410. ]
  411. ];
  412. } elseif ($store_mini->batch_status == 1 || $store_mini->batch_status == 4) {//创建事务成功
  413. return [
  414. 'code'=>0,
  415. 'msg'=>"需要签约当面付",
  416. 'data'=>[
  417. 'status'=>1,
  418. 'bind_store_id' => $store_id,
  419. 'mini_id' => $mini_id,
  420. 'progress' => 3,
  421. 'business_model' => $store->business_model
  422. ]
  423. ];
  424. } elseif ($store_mini->batch_status == 2) {//签约当面付成功
  425. return [
  426. 'code'=>0,
  427. 'msg'=>"需要审核当面付",
  428. 'data'=>[
  429. 'status'=>2,
  430. 'bind_store_id' => $store_id,
  431. 'mini_id' => $mini_id,
  432. 'progress' => 3,
  433. 'business_model' => $store->business_model
  434. ]
  435. ];
  436. } elseif ($store_mini->batch_status == 3) {//审核中
  437. return [
  438. 'code'=>0,
  439. 'msg'=>"审核中",
  440. 'data'=>[
  441. 'status'=>3,
  442. 'bind_store_id' => $store_id,
  443. 'mini_id' => $mini_id,
  444. 'progress' => 3,
  445. 'business_model' => $store->business_model
  446. ]
  447. ];
  448. } elseif ($store_mini->batch_status == 5) {//等待商户确认
  449. return [
  450. 'code'=>0,
  451. 'msg'=>"等待商户确认",
  452. 'data'=>[
  453. 'status'=>5,
  454. 'bind_store_id' => $store_id,
  455. 'mini_id' => $mini_id,
  456. 'progress' => 3,
  457. 'business_model' => $store->business_model
  458. ]
  459. ];
  460. }
  461. if ($store_mini->batch_status == 8) {//审核失败
  462. return [
  463. 'code'=>0,
  464. 'msg'=>"审核失败",
  465. 'data'=>[
  466. 'status' => 6,
  467. 'reason' => $result->reject_reason,
  468. 'bind_store_id' => $store_id,
  469. 'mini_id' => $mini_id,
  470. 'progress' => 3,
  471. 'business_model' => $store->business_model
  472. ]
  473. ];
  474. }
  475. return $this->phoneMiniStatus();
  476. } catch (\Exception $e) {
  477. return [
  478. 'code' => 0,
  479. 'msg' => $e->getMessage(),
  480. 'data' => [
  481. 'progress' => 3,
  482. 'status' => 7
  483. ]
  484. ];
  485. }
  486. }
  487. public function phoneMiniStatus()
  488. {
  489. try {
  490. /**
  491. * 手机号字段申请
  492. * status = 0 需要获取手机号权限
  493. * status = 1 手机号权限申请中
  494. * status = 2 申请失败
  495. */
  496. //商城ID
  497. goto Register;
  498. $store_id = $this->store_id;
  499. $store = Store::findOne($store_id);
  500. // if ((int)$store->business_model !== 1) {
  501. // goto Register;
  502. // }
  503. //小程序ID
  504. $mini_id = $this->mini_id;
  505. //小程序Model
  506. $store_mini = $this->store_mini;
  507. //小程序版本信息
  508. $mini_version = $this->mini_version;
  509. $form = new PhoneMiniForm();
  510. $form->mini_id = $mini_id;
  511. $field = $form->getField();
  512. if ($field['code'] != 0) {
  513. throw new \Exception($field['msg']);
  514. }
  515. $result = $form->getPhoneStatus();
  516. if ($result['code'] != 0) {
  517. throw new \Exception($result['msg']);
  518. }
  519. //获取手机号申请资料
  520. $apply_phone_msg = json_decode($store_mini->apply_phone_msg ,true) ?: [];
  521. if ($store_mini->is_get_phone == 0) {
  522. return [
  523. 'code' => 0,
  524. 'msg' => "需要申请接入手机号权限",
  525. 'data' => [
  526. 'status' => 0,
  527. 'field' => $field['data'],
  528. 'bind_store_id' => $store_id,
  529. 'mini_id' => $mini_id,
  530. 'progress' => 4,
  531. 'data' => $apply_phone_msg,
  532. 'business_model' => $store->business_model
  533. ]
  534. ];
  535. }
  536. if ($result['status'] === "AUDIT") {
  537. return [
  538. 'code' => 0,
  539. 'msg' => "手机号权限申请中",
  540. 'data' => [
  541. 'status' => 1,
  542. 'field' => $field['data'],
  543. 'bind_store_id' => $store_id,
  544. 'mini_id' => $mini_id,
  545. 'progress' => 4,
  546. 'data' => $apply_phone_msg,
  547. 'business_model' => $store->business_model
  548. ]
  549. ];
  550. }
  551. if ($result['status'] === "REJECT" || $result['status'] === "INVALID") {
  552. return [
  553. 'code' => 0,
  554. 'msg' => "申请失败" . $store_mini->apply_phone_fail,
  555. 'data' => [
  556. 'status' => 2,
  557. 'reason' => $store_mini->apply_phone_fail,
  558. 'field' => $field['data'],
  559. 'bind_store_id' => $store_id,
  560. 'mini_id' => $mini_id,
  561. 'progress' => 4,
  562. 'data' => $apply_phone_msg,
  563. 'business_model' => $store->business_model
  564. ]
  565. ];
  566. }
  567. Register:
  568. return $this->qrcodeMiniStatus();
  569. } catch (\Exception $e) {
  570. return [
  571. 'code' => 0,
  572. 'msg' => $e->getMessage(),
  573. 'data' => [
  574. 'progress' => 4,
  575. 'status' => 3,
  576. ]
  577. ];
  578. }
  579. }
  580. public function qrcodeMiniStatus()
  581. {
  582. try {
  583. /**
  584. * 二维码绑定
  585. * status = 0 未绑定聚合码
  586. * status = 1 已完成
  587. */
  588. //商城ID
  589. $store_id = $this->store_id;
  590. $store = Store::findOne($store_id);
  591. if ((int)$store->business_model !== 1) {
  592. goto Register;
  593. }
  594. //小程序ID
  595. $mini_id = $this->mini_id;
  596. $AggregateQrcode = AggregateQrcode::find()->where(['or', ['ali_mini_id' => $mini_id], ['store_id' => $store_id]])->one();
  597. if (empty($AggregateQrcode->ali_status)) {
  598. return [
  599. 'code'=>0,
  600. 'msg'=>"未绑定聚合码",
  601. 'data'=>[
  602. 'status' => 0,
  603. 'bind_store_id' => $store_id,
  604. 'mini_id' => $mini_id,
  605. 'progress' => 5,
  606. 'business_model' => $store->business_model,
  607. 'qrcode_id' => $AggregateQrcode->id
  608. ]
  609. ];
  610. }
  611. if ($AggregateQrcode->ali_status == 1) {
  612. Register:
  613. $merchant_info = MerchantInfo::findOne(['bind_store_id' => $store_id, 'is_delete' => 0]);
  614. if (!empty($merchant_info->app_status)) {
  615. $app_status = $merchant_info->app_status;
  616. $app_status = str_replace('2', '', $app_status);
  617. $merchant_info->app_status = $app_status;
  618. $merchant_info->save();
  619. }
  620. return [
  621. 'code'=>0,
  622. 'msg'=>"完成",
  623. 'data'=>[
  624. 'status' => 1,
  625. 'bind_store_id' => $store_id,
  626. 'mini_id' => $mini_id ?? 0,
  627. 'progress' => 6,
  628. 'business_model' => $store->business_model
  629. ]
  630. ];
  631. }
  632. throw new \Exception("参数错误");
  633. } catch (\Exception $e) {
  634. return [
  635. 'code' => 1,
  636. 'msg' => $e->getMessage(),
  637. 'data' => [
  638. 'progress' => 5,
  639. 'status' => 1,
  640. ]
  641. ];
  642. }
  643. }
  644. }