YunstMiniMerchantForm.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use app\models\District;
  9. use app\models\MerchantInfo;
  10. use app\models\Option;
  11. use app\models\StoreMini;
  12. use app\models\StoreSchedule;
  13. use app\models\WechatConfig;
  14. use app\utils\WechatMerchant\Merchant;
  15. use yii\base\Model;
  16. class YunstMiniMerchantForm extends Model
  17. {
  18. public $merchant_info;
  19. public $status;
  20. public $id;
  21. public $is_use;
  22. public function rules()
  23. {
  24. return [
  25. [['merchant_info'], 'array'],
  26. [['status', 'id','is_use'], 'integer']
  27. ];
  28. }
  29. //获取进件参数
  30. public function merchantInfo(){
  31. $store_id = get_store_id();
  32. $id = $this->id;
  33. try {
  34. $MerchantInfo = MerchantInfo::find()->where(['bind_store_id' => $store_id, 'id' => $id, 'is_delete' => 0])->asArray()->one();
  35. // $StoreSchedule = StoreSchedule::find()->where(['store_id' => $store_id])->one();
  36. $merchant_info = [];
  37. // if (!empty($StoreSchedule->merchant_info)) {
  38. // $merchant_info = json_decode($StoreSchedule->merchant_info,true);
  39. // // $business_license_info = $merchant_info['subject_info']['business_license_info'];
  40. // }
  41. if (!empty($MerchantInfo)) {
  42. $merchant_info = $MerchantInfo;
  43. $merchant_info['subject_info'] = json_decode($merchant_info['subject_info'],true) ?: [
  44. 'subject_type' => 'SUBJECT_TYPE_ENTERPRISE',
  45. 'business_license_info' => [
  46. 'license_copy' => '',
  47. 'license_number' => '',
  48. 'merchant_name' => '',
  49. 'legal_person' => ''
  50. ],
  51. 'certificate_info' => [
  52. 'is_long' => '',
  53. 'cert_copy' => '',
  54. 'cert_type' => '',
  55. 'cert_number' => '',
  56. 'merchant_name' => '',
  57. 'company_address' => '',
  58. 'legal_person' => '',
  59. 'period_begin' => '',
  60. 'period_end' => '',
  61. ],
  62. 'organization_info' => [
  63. 'is_composite' => 1,
  64. 'organization_copy' => '',
  65. 'organization_code' => '',
  66. 'org_period_begin' => '',
  67. 'org_period_end' => '',
  68. 'is_long' => 0
  69. ],
  70. 'identity_info' => [
  71. 'is_long' => 0,
  72. 'id_doc_type' => 'IDENTIFICATION_TYPE_IDCARD',
  73. 'id_card_info' => [
  74. 'id_card_copy' => '',
  75. 'id_card_national' => '',
  76. 'id_card_name' => '',
  77. 'id_card_number' => '',
  78. 'card_period_begin' => '',
  79. 'card_period_end' => ''
  80. ],
  81. 'id_doc_info' => [
  82. 'id_doc_copy' => '',
  83. 'id_doc_name' => '',
  84. 'id_doc_number' => '',
  85. 'doc_period_begin' => '',
  86. 'doc_period_end' => ''
  87. ],
  88. 'owner' => true
  89. ]
  90. ];
  91. if (intval($merchant_info['subject_info']['business_license_info']['is_long']) === 1) {
  92. $merchant_info['subject_info']['business_license_info']['period_end'] = '2999-12-31';
  93. }
  94. // $business_license_info = $merchant_info['subject_info']['business_license_info'];
  95. $merchant_info['business_info'] = json_decode($merchant_info['business_info'],true) ?: [
  96. 'merchant_shortname' => '',
  97. 'service_phone' => '',
  98. 'sales_info' => [
  99. 'sales_scenes_type' => [
  100. ''
  101. ],
  102. 'mini_program_info' => [
  103. 'mini_program_appid' => ''
  104. ]
  105. ]
  106. ];
  107. $merchant_info['settlement_info'] = json_decode($merchant_info['settlement_info'],true) ?: [];
  108. $merchant_info['bank_account_info'] = json_decode($merchant_info['bank_account_info'],true) ?: [
  109. 'bank_account_type' => '',
  110. 'account_name' => '',
  111. 'account_bank' => '',
  112. 'bank_address_code' => '',
  113. 'account_number' => '',
  114. 'code_list' => [
  115. ],
  116. 'address_list' => [
  117. ]
  118. ];
  119. $merchant_info['contact_info'] = json_decode($merchant_info['contact_info'],true) ?: [
  120. 'contact_name' => '',
  121. 'contact_id_number' => '',
  122. 'mobile_phone' => '',
  123. 'contact_email' => ''
  124. ];
  125. }
  126. return [
  127. 'code' => 0,
  128. 'msg' => "获取成功",
  129. 'data' => $merchant_info
  130. ];
  131. } catch (\Exception $e) {
  132. return [
  133. 'code' => 1,
  134. 'msg' => $e->getMessage()
  135. ];
  136. }
  137. }
  138. //保存进件参数
  139. public function save(){
  140. $store_id = get_store_id();
  141. //商户进件信息ID
  142. $id = $this->id;
  143. //post商户ID
  144. $merchant_info = $this->merchant_info;
  145. $appid ='';
  146. $Merchant = new \app\utils\yunst\src\Merchant();
  147. return $Merchant->submit($merchant_info['contact_info'], $merchant_info['subject_info'], $merchant_info['business_info'], $merchant_info['bank_account_info'], $id, $appid, $store_id, $merchant_info['settlement_info']);
  148. }
  149. //获取进件列表
  150. public function list()
  151. {
  152. $store_id = get_store_id();
  153. $status = $this->status;
  154. \Yii::error($status,"这还是status");
  155. //保存商户信息
  156. $query = MerchantInfo::find()->where(['bind_store_id'=>$store_id, 'is_delete' => 0])->select('id, status, refuse_desc, sub_mch_id, business_code, created_at, updated_at, subject_info, sign_url, state, is_use');
  157. if ($status != -1) {
  158. $query->andWhere(['status' => $status]);
  159. }
  160. $query->orderBy(['id' => SORT_DESC]);
  161. \Yii::error($query->createCommand()->getRawSql());
  162. $pagination = pagination_make($query);
  163. $merchant_info = $pagination['list'];
  164. array_walk($merchant_info, function (&$item) {
  165. $item['created_at'] = date("Y-m-d H:i:s", $item['created_at']);
  166. $item['updated_at'] = date("Y-m-d H:i:s", $item['updated_at']);
  167. $subject_info = json_decode($item['subject_info'], true);
  168. $item['type'] = $subject_info['subject_type'];
  169. switch ($item['type']) {
  170. case "SUBJECT_TYPE_INDIVIDUAL":
  171. $item['type'] = "个体户";
  172. break;
  173. case "SUBJECT_TYPE_ENTERPRISE":
  174. $item['type'] = "企业";
  175. break;
  176. case "SUBJECT_TYPE_GOVERNMENT":
  177. $item['type'] = "政府机关";
  178. break;
  179. case "SUBJECT_TYPE_INSTITUTIONS":
  180. $item['type'] = "事业单位";
  181. break;
  182. case "SUBJECT_TYPE_OTHERS":
  183. $item['type'] = "社会组织";
  184. break;
  185. }
  186. if($item['sign_url']){
  187. $sign_url = json_decode($item['sign_url'], true);
  188. $item['sign_url'] = $sign_url['applyment_state_msg'] . '<br/> <img width="300" height="300" src="' .$sign_url['sign_url']. '"/>';
  189. }
  190. if ($item['state'] === 'APPLYMENT_STATE_TO_BE_SIGNED' && (int)$item['status'] === 1) {
  191. $item['status'] = '4';
  192. };
  193. // if ((int)$item['status'] == 2 && !empty($item['refuse_desc'])) {
  194. // $refuse_desc = json_decode($item['refuse_desc'], true);
  195. // $item['refuse_desc'] = '';
  196. // foreach ($refuse_desc as $val) {
  197. // $item['refuse_desc'] .= $val['field'] . ':' . $val['reject_reason'] . ';';
  198. // }
  199. // }
  200. $item['state_str'] = $item['state'] ? Merchant::$valid_state_desc[$item['state']] : '审核中';
  201. unset($item['subject_info']);
  202. });
  203. return [
  204. 'code' => 0,
  205. 'msg' => "获取成功",
  206. 'data' => $merchant_info,
  207. 'pageNo' => $pagination['pageNo'],
  208. 'totalCount' => $pagination['totalCount']
  209. ];
  210. }
  211. public function getCountry(){
  212. $District = District::find()->asArray()->all();
  213. $data = $this->getdata($District);
  214. return [
  215. 'code' => 0,
  216. 'msg' => "获取成功",
  217. 'data' => $data
  218. ];
  219. }
  220. //递归
  221. public function getdata($data, $id = 0)
  222. {
  223. $arr = [];
  224. foreach ($data as $k => $v) {
  225. if ($v['parent_id'] == $id) {
  226. $v['children'] = $this->getdata($data, $v['id']);
  227. $arr[] = $v;
  228. }
  229. }
  230. return $arr;
  231. }
  232. /**
  233. * 暂停/开始使用
  234. */
  235. public function unbind()
  236. {
  237. try {
  238. $merchant = MerchantInfo::findOne(['id' => $this->id, 'is_delete' => 0]);
  239. if (empty($merchant)) {
  240. throw new \Exception("数据错误,获取小程序信息失败");
  241. }
  242. $store_id = get_store_id();
  243. if ($this->is_use == 1 || empty($this->is_use)) {
  244. MerchantInfo::updateAll(['is_use' => 2], ['bind_store_id' => $store_id, 'is_delete' => 0]);
  245. $merchant->is_use = 1;
  246. } elseif ($this->is_use == 2) {
  247. $merchant->is_use = 2;
  248. }
  249. $res = $merchant->save();
  250. if ($res) {
  251. //设置店铺的appid
  252. if($merchant->is_use == 1){
  253. $merchant_name = '';
  254. if(isset($merchant['subject_info']) && !empty($merchant['subject_info'])){
  255. $subject_info = json_decode($merchant['subject_info'],true);
  256. if(isset($subject_info['business_license_info']['merchant_name']) && !empty($subject_info['business_license_info']['merchant_name'])){
  257. $merchant_name = $subject_info['business_license_info']['merchant_name'];
  258. }
  259. }
  260. $wechat = WechatConfig::find()->where(['store_id'=>$store_id,'type'=>1,'is_delete'=>0])->one();
  261. $wechat->mch_id = $merchant->sub_mch_id;
  262. $wechat->name = $merchant_name;
  263. $wechat->save();
  264. }
  265. return [
  266. 'code' => 0,
  267. 'msg' => "设置成功",
  268. 'data' => $res
  269. ];
  270. } else {
  271. throw new \Exception("数据库添加失败");
  272. }
  273. } catch (\Exception $e) {
  274. return [
  275. 'code' => 1,
  276. 'msg' => $e->getMessage()
  277. ];
  278. }
  279. }
  280. }