| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\District;
- use app\models\MerchantInfo;
- use app\models\Option;
- use app\models\StoreMini;
- use app\models\StoreSchedule;
- use app\models\WechatConfig;
- use app\utils\WechatMerchant\Merchant;
- use yii\base\Model;
- class YunstMiniMerchantForm extends Model
- {
- public $merchant_info;
- public $status;
- public $id;
- public $is_use;
- public function rules()
- {
- return [
- [['merchant_info'], 'array'],
- [['status', 'id','is_use'], 'integer']
- ];
- }
- //获取进件参数
- public function merchantInfo(){
- $store_id = get_store_id();
- $id = $this->id;
- try {
- $MerchantInfo = MerchantInfo::find()->where(['bind_store_id' => $store_id, 'id' => $id, 'is_delete' => 0])->asArray()->one();
- // $StoreSchedule = StoreSchedule::find()->where(['store_id' => $store_id])->one();
- $merchant_info = [];
- // if (!empty($StoreSchedule->merchant_info)) {
- // $merchant_info = json_decode($StoreSchedule->merchant_info,true);
- // // $business_license_info = $merchant_info['subject_info']['business_license_info'];
- // }
- if (!empty($MerchantInfo)) {
- $merchant_info = $MerchantInfo;
- $merchant_info['subject_info'] = json_decode($merchant_info['subject_info'],true) ?: [
- 'subject_type' => 'SUBJECT_TYPE_ENTERPRISE',
- 'business_license_info' => [
- 'license_copy' => '',
- 'license_number' => '',
- 'merchant_name' => '',
- 'legal_person' => ''
- ],
- 'certificate_info' => [
- 'is_long' => '',
- 'cert_copy' => '',
- 'cert_type' => '',
- 'cert_number' => '',
- 'merchant_name' => '',
- 'company_address' => '',
- 'legal_person' => '',
- 'period_begin' => '',
- 'period_end' => '',
- ],
- 'organization_info' => [
- 'is_composite' => 1,
- 'organization_copy' => '',
- 'organization_code' => '',
- 'org_period_begin' => '',
- 'org_period_end' => '',
- 'is_long' => 0
- ],
- 'identity_info' => [
- 'is_long' => 0,
- 'id_doc_type' => 'IDENTIFICATION_TYPE_IDCARD',
- 'id_card_info' => [
- 'id_card_copy' => '',
- 'id_card_national' => '',
- 'id_card_name' => '',
- 'id_card_number' => '',
- 'card_period_begin' => '',
- 'card_period_end' => ''
- ],
- 'id_doc_info' => [
- 'id_doc_copy' => '',
- 'id_doc_name' => '',
- 'id_doc_number' => '',
- 'doc_period_begin' => '',
- 'doc_period_end' => ''
- ],
- 'owner' => true
- ]
- ];
- if (intval($merchant_info['subject_info']['business_license_info']['is_long']) === 1) {
- $merchant_info['subject_info']['business_license_info']['period_end'] = '2999-12-31';
- }
- // $business_license_info = $merchant_info['subject_info']['business_license_info'];
- $merchant_info['business_info'] = json_decode($merchant_info['business_info'],true) ?: [
- 'merchant_shortname' => '',
- 'service_phone' => '',
- 'sales_info' => [
- 'sales_scenes_type' => [
- ''
- ],
- 'mini_program_info' => [
- 'mini_program_appid' => ''
- ]
- ]
- ];
- $merchant_info['settlement_info'] = json_decode($merchant_info['settlement_info'],true) ?: [];
- $merchant_info['bank_account_info'] = json_decode($merchant_info['bank_account_info'],true) ?: [
- 'bank_account_type' => '',
- 'account_name' => '',
- 'account_bank' => '',
- 'bank_address_code' => '',
- 'account_number' => '',
- 'code_list' => [
- ],
- 'address_list' => [
- ]
- ];
- $merchant_info['contact_info'] = json_decode($merchant_info['contact_info'],true) ?: [
- 'contact_name' => '',
- 'contact_id_number' => '',
- 'mobile_phone' => '',
- 'contact_email' => ''
- ];
- }
- return [
- 'code' => 0,
- 'msg' => "获取成功",
- 'data' => $merchant_info
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
- //保存进件参数
- public function save(){
- $store_id = get_store_id();
- //商户进件信息ID
- $id = $this->id;
- //post商户ID
- $merchant_info = $this->merchant_info;
- $appid ='';
- $Merchant = new \app\utils\yunst\src\Merchant();
- 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']);
- }
- //获取进件列表
- public function list()
- {
- $store_id = get_store_id();
- $status = $this->status;
- \Yii::error($status,"这还是status");
- //保存商户信息
- $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');
- if ($status != -1) {
- $query->andWhere(['status' => $status]);
- }
- $query->orderBy(['id' => SORT_DESC]);
- \Yii::error($query->createCommand()->getRawSql());
- $pagination = pagination_make($query);
- $merchant_info = $pagination['list'];
- array_walk($merchant_info, function (&$item) {
- $item['created_at'] = date("Y-m-d H:i:s", $item['created_at']);
- $item['updated_at'] = date("Y-m-d H:i:s", $item['updated_at']);
- $subject_info = json_decode($item['subject_info'], true);
- $item['type'] = $subject_info['subject_type'];
- switch ($item['type']) {
- case "SUBJECT_TYPE_INDIVIDUAL":
- $item['type'] = "个体户";
- break;
- case "SUBJECT_TYPE_ENTERPRISE":
- $item['type'] = "企业";
- break;
- case "SUBJECT_TYPE_GOVERNMENT":
- $item['type'] = "政府机关";
- break;
- case "SUBJECT_TYPE_INSTITUTIONS":
- $item['type'] = "事业单位";
- break;
- case "SUBJECT_TYPE_OTHERS":
- $item['type'] = "社会组织";
- break;
- }
- if($item['sign_url']){
- $sign_url = json_decode($item['sign_url'], true);
- $item['sign_url'] = $sign_url['applyment_state_msg'] . '<br/> <img width="300" height="300" src="' .$sign_url['sign_url']. '"/>';
- }
- if ($item['state'] === 'APPLYMENT_STATE_TO_BE_SIGNED' && (int)$item['status'] === 1) {
- $item['status'] = '4';
- };
- // if ((int)$item['status'] == 2 && !empty($item['refuse_desc'])) {
- // $refuse_desc = json_decode($item['refuse_desc'], true);
- // $item['refuse_desc'] = '';
- // foreach ($refuse_desc as $val) {
- // $item['refuse_desc'] .= $val['field'] . ':' . $val['reject_reason'] . ';';
- // }
- // }
- $item['state_str'] = $item['state'] ? Merchant::$valid_state_desc[$item['state']] : '审核中';
- unset($item['subject_info']);
- });
- return [
- 'code' => 0,
- 'msg' => "获取成功",
- 'data' => $merchant_info,
- 'pageNo' => $pagination['pageNo'],
- 'totalCount' => $pagination['totalCount']
- ];
- }
- public function getCountry(){
- $District = District::find()->asArray()->all();
- $data = $this->getdata($District);
- return [
- 'code' => 0,
- 'msg' => "获取成功",
- 'data' => $data
- ];
- }
- //递归
- public function getdata($data, $id = 0)
- {
- $arr = [];
- foreach ($data as $k => $v) {
- if ($v['parent_id'] == $id) {
- $v['children'] = $this->getdata($data, $v['id']);
- $arr[] = $v;
- }
- }
- return $arr;
- }
- /**
- * 暂停/开始使用
- */
- public function unbind()
- {
- try {
- $merchant = MerchantInfo::findOne(['id' => $this->id, 'is_delete' => 0]);
- if (empty($merchant)) {
- throw new \Exception("数据错误,获取小程序信息失败");
- }
- $store_id = get_store_id();
- if ($this->is_use == 1 || empty($this->is_use)) {
- MerchantInfo::updateAll(['is_use' => 2], ['bind_store_id' => $store_id, 'is_delete' => 0]);
- $merchant->is_use = 1;
- } elseif ($this->is_use == 2) {
- $merchant->is_use = 2;
- }
- $res = $merchant->save();
- if ($res) {
- //设置店铺的appid
- if($merchant->is_use == 1){
- $merchant_name = '';
- if(isset($merchant['subject_info']) && !empty($merchant['subject_info'])){
- $subject_info = json_decode($merchant['subject_info'],true);
- if(isset($subject_info['business_license_info']['merchant_name']) && !empty($subject_info['business_license_info']['merchant_name'])){
- $merchant_name = $subject_info['business_license_info']['merchant_name'];
- }
- }
- $wechat = WechatConfig::find()->where(['store_id'=>$store_id,'type'=>1,'is_delete'=>0])->one();
- $wechat->mch_id = $merchant->sub_mch_id;
- $wechat->name = $merchant_name;
- $wechat->save();
- }
- return [
- 'code' => 0,
- 'msg' => "设置成功",
- 'data' => $res
- ];
- } else {
- throw new \Exception("数据库添加失败");
- }
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- }
-
- }
|