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; //判断是否是三方的小程序 $wechat = WechatConfig::find()->where(['store_id'=>$store_id])->select('app_id')->one(); if(!empty($wechat->app_id)){ $appid = $wechat->app_id; $mini = StoreMini::find()->where(['store_id' => $store_id, 'appid' => $appid])->orderBy('id desc')->select('appid')->one(); } //如果不是三方的小程序则使用系统默认的小程序 if (empty($mini)) { $appid = ""; } $self_mini = Option::get('self_mini', $store_id, 'store', 0)['value']; if (\Yii::$app->prod_is_dandianpu() && !$self_mini) { $appid = Option::get('one_store_wechat_appid', 0, 'saas', '')['value']; } $Merchant = new 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->andWhere(['is_yunst' => 0]); $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'] . '
'; } if (in_array($item['state'], [Merchant::APPLYMENT_STATE_TO_BE_SIGNED, Merchant::APPLYMENT_STATE_TO_BE_CONFIRMED]) && (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 list2() { $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->andWhere(['is_yunst'=>1]); $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'] . '
'; } 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'] . ';'; // } // } if ($item['state'] == '00'){ $item['state_str'] = '待审核'; }elseif ($item['state'] == '01'){ $item['state_str'] = '审核中'; }elseif ($item['state'] == '02'){ $item['state_str'] = '审核通过'; }elseif ($item['state'] == '03'){ $item['state_str'] = '审核失败'; }elseif ($item['state'] == '04'){ $item['state_str'] = '提交审核失败'; } if ($item['status'] == 1){ $item['state_str'] = '审核中'; } // $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()->where(['level' => ['country', 'province', 'city', 'district']])->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) { $children = $this->getdata($data, $v['id']); $v['children'] = $children ? $children : null; $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_type_arr = [ WechatConfig::TYPE_CONFIG_MINI, WechatConfig::TYPE_CONFIG_MP, WechatConfig::TYPE_CONFIG_APP, WechatConfig::TYPE_CONFIG_H5 ]; foreach ($wechat_type_arr as $wechat_type_value) { $wechat = WechatConfig::findOne(['store_id' => $store_id, 'type' => $wechat_type_value, 'is_delete' => 0]); if (!$wechat) { $wechat = new WechatConfig(); $wechat->store_id = $store_id; $wechat->type = $wechat_type_value; $wechat->app_id = 'app_id'; $wechat->app_secret = 'app_secret'; } $wechat->mch_id = $merchant->sub_mch_id; $wechat->name = $merchant_name; $wechat->updated_at = time(); $wechat->save(); } } return [ 'code' => 0, 'msg' => "设置成功", 'data' => $res ]; } else { throw new \Exception("数据库添加失败"); } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function deleteMerchantInfo() { $id = $this->id; $merchant_info = MerchantInfo::findOne(['id' => $id, 'is_delete' => 0]); if (!$merchant_info) { return [ 'code' => 0, 'msg' => '操作成功' ]; } $merchant_info->is_delete = 1; if (!$merchant_info->save()) { return [ 'code' => 1, 'msg' => '操作失败:' . json_encode($merchant_info->errors, JSON_UNESCAPED_UNICODE) ]; }; return [ 'code' => 0, 'msg' => '操作成功' ]; } //绑定商户号 非进件逻辑需要添加进件数据 public function setTemporaryInfo() { $appid = $this->appid; $mch_id = $this->mch_id; $subject_type = $this->subject_type; $merchant_info = $this->merchant_info; $store_id = $this->store_id; if (\Yii::$app->request->isPost) { if (!in_array($subject_type, [ "SUBJECT_TYPE_INDIVIDUAL", "SUBJECT_TYPE_ENTERPRISE", "SUBJECT_TYPE_GOVERNMENT", "SUBJECT_TYPE_INSTITUTIONS", "SUBJECT_TYPE_OTHERS" ])) { return [ 'code' => 1, 'msg' => '企业类型所选值错误' ]; } $merchant = new MerchantInfo(); $merchant->store_id = $store_id; $merchant->saas_user_id = 0; $merchant->business_code = ""; $merchant->contact_info = json_encode([ 'contact_name' => '', 'contact_id_number' => '', 'mobile_phone' => '', 'contact_email' => '' ], JSON_UNESCAPED_UNICODE); $merchant->subject_info = json_encode([ 'subject_type' => $subject_type, 'business_license_info' => [ 'license_copy' => '', 'license_number' => '', 'merchant_name' => $merchant_info, '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 ] ], JSON_UNESCAPED_UNICODE); $merchant->settlement_info = json_encode([]);; $merchant->business_info = json_encode([ 'merchant_shortname' => '', 'service_phone' => '', 'sales_info' => [ 'sales_scenes_type' => [ '' ], 'mini_program_info' => [ 'mini_program_appid' => $appid ] ] ], JSON_UNESCAPED_UNICODE); $merchant->bank_account_info = json_encode([]); $merchant->applyment_id = ""; $merchant->status = 3; $merchant->state = "APPLYMENT_STATE_FINISHED"; $merchant->bind_store_id = $store_id; $merchant->sub_mch_id = $mch_id; if (!$merchant->save()) { return [ 'code' => 1, 'msg' => implode(';', array_values($merchant->firstErrors)) ]; } return [ 'code' => 0, 'msg' => '保存成功' ]; } else { $app_config = []; $app = WechatMini::getWechatConfig($store_id); if (!empty($app)) { $app_config = $app->getConfig(); } return [ 'code' => 0, 'msg' => '获取成功', 'data' => [ 'appid' => $app_config['app_id'] ?? '' ] ]; } } }