| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\models\v1;
- use app\models\Admin;
- use app\models\AggregateQrcode;
- use app\models\MerchantInfo;
- use app\models\Option;
- use app\models\SaasCategory;
- use app\models\SaasStoreReferral;
- use app\models\SaasUser;
- use app\models\Salesman;
- use app\models\SharingReceiver;
- use app\models\Store;
- use app\models\StoreAliMini;
- use app\models\StoreAliMiniVersion;
- use app\models\StoreAudit;
- use app\models\StoreMini;
- use app\models\StoreSchedule;
- use app\modules\admin\models\AlipayThirdForm;
- use app\modules\admin\models\WechatThirdErrorMsgForm;
- use app\modules\admin\models\WechatThirdForm;
- use app\utils\WechatMerchant\Merchant;
- use yii\base\Model;
- use EasyWeChat\Factory;
- use yii\data\Pagination;
- class NewSalesmanForm extends Model
- {
- public $contact_info;
- public $subject_info;
- public $business_info;
- public $bank_account_info;
- public $mini_apply_info;
- public $type = 'weixin'; //'weixin'
- public $code;
- public $id;
- public $qrcode_id;
- public $page;
- public $status;
- public $sort;
- public $mini_id;
- public $category_id;
- public $merchant_info_id;
- public $store_id;
- public $bind_store_id;
- public $openPlatform;
- public function rules()
- {
- return [
- [["license_pic", "license_no", "license_name", "legal_personal_name", "contact_info", "subject_info", "business_info", "bank_account_info", "type","code","pay_fee"], 'string'],
- [["apply_id","id",'qrcode_id', "page", "status", "sort", "category_id",'store_id','merchant_info_id','bind_store_id','mini_id'], "integer"],
- [["mini_apply_info"], "array"]
- ];
- }
- public function __construct($config = [])
- {
- parent::__construct($config);
- $config = [
- 'app_id' => Option::get("platform_third_appid",0,'saas')['value'],
- 'secret' => Option::get("platform_third_secret",0,'saas')['value'],
- 'token' => Option::get("platform_token",0,'saas')['value'],
- 'aes_key' => Option::get("platform_encodingAesKey",0,'saas')['value']
- ];
- $this->store_id = !empty($this->store_id)?$this->store_id:get_store_id();
- $this->openPlatform = Factory::openPlatform($config);
- }
- //返回中文错误信息
- public function getZnMsg($result){
- $ErrorMsg = new WechatThirdErrorMsgForm();
- $arr = $ErrorMsg->getArray();
- $msg = !empty($arr[$result['errcode']])?$arr[$result['errcode']]:$result['errmsg'];
- return $msg;
- }
- //TODO 商户逻辑 start
- public function saveMerchant(){
- //保存商户信息
- $merchant_info = MerchantInfo::find()->where(['bind_store_id'=>$this->bind_store_id, 'is_delete' => 0])->one();
- $mini = StoreMini::find()->where(['store_id'=>$this->bind_store_id])->orderBy('id desc')->select('appid')->one();
- if(empty($merchant_info) || empty($mini->appid)){
- return [
- 'code' => 1,
- 'msg' =>"参数错误"
- ];
- }
- $Merchant = new Merchant();
- return $Merchant->submit(json_decode($this->contact_info,true),json_decode($this->subject_info,true),json_decode($this->business_info,true),json_decode($this->bank_account_info,true),$merchant_info->id,$mini->appid);
- }
- public function getMerchant(){
- $StoreSchedule = StoreSchedule::find()->where(['audit_id'=>$this->id])->select('merchant_info')->one();
- return [
- 'code'=>0,
- 'msg'=>"",
- 'data'=>$StoreSchedule
- ];
- }
- //申请小程序
- public function applyMini(){
- $saas_user_id = get_saas_user_id();
- $mini_apply_info = $this->mini_apply_info;
- $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
- if($this->type == "weixin"){
- $form = new WechatThirdForm();
- $form->name = $mini_apply_info->license_name;
- $form->code = $mini_apply_info->license_no;
- $form->code_type = $mini_apply_info->code_type;
- $form->legal_persona_wechat = $mini_apply_info->legal_persona_account;
- $form->legal_persona_name = $mini_apply_info->legal_persona_name;
- $form->license_pic = $mini_apply_info->license_pic;
- $form->bind_store_id = $this->bind_store_id;
- $res = $form->fastRegisterMini();
- if($res['code'] === 0){
- if(!empty($this->bind_store_id)){
- $qrcode = AggregateQrcode::find()->where(['store_id'=>$this->bind_store_id])->one();
- if(!empty($qrcode)){
- $qrcode->wx_mini_id = $res['data'];
- $res = $qrcode->save();
- if($res){
- return [
- 'code'=>0,
- 'msg'=>"开始审核,绑定聚合码成功"
- ];
- }
- }
- }
- $res = [
- 'code'=>0,
- 'msg'=>"开始审核,聚合码未绑定"
- ];
- }
- }elseif($this->type == "ali"){
- $form = new AlipayThirdForm();
- $form->license_name = $mini_apply_info->license_name;
- $form->license_no = $mini_apply_info->license_no;
- $form->alipay_account = $mini_apply_info->legal_persona_account;
- $form->legal_personal_name = $mini_apply_info->legal_persona_name;
- $form->AppName = $mini_apply_info->app_name;
- $form->ServicePhone = $mini_apply_info->service_phone;
- $form->contact_name = $mini_apply_info->contact_name;
- $form->license_pic = $mini_apply_info->license_pic;
- $form->bind_store_id = $this->bind_store_id;
- $res = $form->isvCreateMini();
- if($res['code'] === 0){
- if(!empty($this->bind_store_id)){
- $qrcode = AggregateQrcode::find()->where(['store_id'=>$this->bind_store_id])->one();
- if(!empty($qrcode)){
- $qrcode->ali_mini_id = $res['id'];
- $res = $qrcode->save();
- if($res){
- return [
- 'code'=>0,
- 'msg'=>"开始审核,绑定聚合码成功"
- ];
- }
- }
- }
- $res = [
- 'code'=>0,
- 'msg'=>"开始审核,聚合码未绑定"
- ];
- }
- }else{
- $res = [
- 'code'=>1,
- 'msg'=>"未知的申请方式"
- ];
- }
- return $res;
- }
- //绑定收款码
- public function bindPayQrcode(){
- $bind_store_id = !empty($this->bind_store_id) ? $this->bind_store_id : get_store_id();
- if (!empty($this->bind_store_id)){
- $saas_user_id = get_saas_user_id();
- $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
- $AggregateQrcode = AggregateQrcode::find()->where([
- 'or',
- ['id' => $this->qrcode_id],
- ['store_id' => $bind_store_id]
- ])->one();
- } else{
- $AggregateQrcode = AggregateQrcode::find()->where(['store_id' => $bind_store_id])->one();
- if(empty($AggregateQrcode->salesman_id)){
- return [
- 'code'=>1,
- 'msg'=>"请绑定业务员"
- ];
- }
- $salesman = Salesman::findOne($AggregateQrcode->salesman_id);
- }
- // \Yii::error(json_encode($AggregateQrcode));
- if (empty($AggregateQrcode)){
- return [
- 'code'=>1,
- 'msg'=>"聚合码不存在"
- ];
- }
- if (empty($AggregateQrcode->ali_status) || empty($AggregateQrcode->wx_status)){
- if ($this->type == "weixin" || empty($this->type)){
- $form = StoreMini::find()->where(['store_id'=>$bind_store_id])->orderBy('id desc')->select('id,appid')->asArray()->one();
- $mini_id = !empty($this->mini_id)?$this->mini_id:$form['id'];
- $AggregateQrcode->wx_mini_id = $mini_id;
- } elseif($this->type == "ali"){
- $form = StoreAliMini::find()->where(['store_id'=>$bind_store_id])->orderBy('id desc')->select('id,auth_app_id appid')->asArray()->one();
- $mini_id = !empty($this->mini_id)?$this->mini_id:$form['id'];
- $AggregateQrcode->ali_mini_id = $mini_id;
- }
- if (empty($form['appid'])){
- return [
- 'code'=>1,
- 'msg'=>"没有找到任何的小程序或小程序未创建完成"
- ];
- }
- $AggregateQrcode->store_id = $bind_store_id;
- $AggregateQrcode->mini_time = time();
- if (empty($AggregateQrcode->salesman_id)){
- $AggregateQrcode->salesman_id = $salesman->id;
- $AggregateQrcode->admin_id = $salesman->admin_id;
- }
- $res = $AggregateQrcode->save();
-
- if ($res){
- if ($this->type == "ali"){
- $form = new AlipayThirdForm();
- $res = $form->bindQrcode($AggregateQrcode->ali_mini_id);
- if ($res['code'] != 0){
- return [
- 'code'=>1,
- 'msg'=>'绑定失败'
- ];
- }
- $MerchantInfo = MerchantInfo::find()->where([ 'bind_store_id' => $bind_store_id, 'is_delete' => 0])->orderBy('id desc')->one();
- if (!empty($MerchantInfo) && !empty($this->bind_store_id)){
- $str = $MerchantInfo->app_status;
- $str_arr = explode(',', $str);
- // 判断当前数组是否包含1
- if (in_array(2, $str_arr)) {
- $string = count($str_arr) > 1 ? '1' : '0';
- $MerchantInfo->app_status = $string;
- }
- if (!$MerchantInfo->save()){
- return [
- 'code'=>1,
- 'msg'=>json_encode($MerchantInfo->errors)
- ];
- }
- }
- return [
- 'code'=>0,
- 'msg'=>"绑定成功"
- ];
- }elseif($this->type == "weixin" || empty($this->type)){
- $wechat = new WechatThirdForm();
- $wechat->bind_store_id = $bind_store_id;
- $res = $wechat->downQrcodeRules($form['id'],$form['appid']);
- if($res['code'] === 0){
- $MerchantInfo = MerchantInfo::find()->where(['bind_store_id' => $bind_store_id, 'is_delete' => 0])->orderBy('id desc')->one();
-
- if(!empty($MerchantInfo) && !empty($this->bind_store_id)){
- $str = $MerchantInfo->app_status;
- $str_arr = explode(',', $str);
- // 判断当前数组是否包含1
- if(in_array(1, $str_arr)) {
- $string = count($str_arr) > 1 ? '2' : '0';
- $MerchantInfo->app_status = $string;
- }
- if(!$MerchantInfo->save()){
- return [
- 'code'=>1,
- 'msg'=>json_encode($MerchantInfo->errors)
- ];
- }
- }
- return [
- 'code'=>0,
- 'msg'=>"绑定成功"
- ];
- }else{
- return [
- 'code'=>1,
- 'msg'=>$res['msg']
- ];
- }
- }else{
- return [
- 'code'=>1,
- 'msg'=>'使用未知的系统'
- ];
- }
- }else{
- return [
- 'code'=>1,
- 'msg'=>'绑定失败'
- ];
- }
- }else{
- return [
- 'code'=>1,
- 'msg'=>'已经绑定完成,请勿重复绑定'
- ];
- }
- }
- //获取进度信息
- public function getProgress(){//注册小程序-进件状态-小程序完善状态-绑定二维码状态
- if(empty($this->bind_store_id)){
- return [
- 'code'=>1,
- 'msg'=>"参数错误",
- 'data'=>[
- 'num'=>2,
- 'progress'=>1
- ]
- ];
- }
- $MerchantInfo = MerchantInfo::find()->where(['bind_store_id'=>$this->bind_store_id, 'is_delete' => 0])->select('id,status,bind_store_id,refuse_desc,contact_info,subject_info,business_info,bank_account_info,applyment_id')->orderBy('id desc')->asArray()->one();
- $StoreSchedule = StoreSchedule::find()->where(['store_id'=>$this->bind_store_id])->one();
- $StoreAudit = StoreAudit::find()->where(['merchant_info_id'=>$MerchantInfo['id']])->select("name,logo")->asArray()->one();
- $form = new WechatThirdForm();
- $form->bind_store_id = $this->bind_store_id;
- $all_categories = $form->getAllCategories();
- $all_category = [];
- $all_old_category = [];
- if($all_categories['code'] === 0){
- $all_old_category = $all_categories['old_data'];
- $all_category = $all_categories['data'][0]['children'];
- }
- if($this->type == 'ali'){
- $form = new AlipayThirdForm();
- $form->bind_store_id = $this->bind_store_id;
- $all_categories = $form->getCategoryList();
- if($all_categories['code'] === 0){
- $all_category = $all_categories['data'];
- }
- }
- $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($MerchantInfo['status'] > 0){
- $merchant_info = $MerchantInfo;
- $merchant_info['subject_info'] = !empty($merchant_info['subject_info'])?json_decode($merchant_info['subject_info'],true):[];
- $business_license_info = $merchant_info['subject_info']['business_license_info'];
- $merchant_info['business_info'] = !empty($merchant_info['business_info'])?json_decode($merchant_info['business_info'],true):[];
- $merchant_info['settlement_info'] = !empty($merchant_info['settlement_info'])?json_decode($merchant_info['settlement_info'],true):[];
- $merchant_info['bank_account_info'] = !empty($merchant_info['bank_account_info'])?json_decode($merchant_info['bank_account_info'],true):[];
- $merchant_info['contact_info'] = !empty($merchant_info['contact_info'])?json_decode($merchant_info['contact_info'],true):[];
-
- }
- // \Yii::error($merchant_info);
- if($this->type == "weixin"){
- $mini = StoreMini::find()->where(['store_id'=>$this->bind_store_id])
- ->orderBy('id desc')
- ->select('id,status,msg,mini_up,mini_up_error,name license_name,apply_name_status,apply_name_error,code license_no,code_type,legal_persona_wechat legal_persona_account,legal_persona_name,license_pic,mini_url,signature,mini_nickname,categories')
- ->asArray()->one();
- $mini_data = [
- 'mini_url'=>!empty($mini['mini_url'])?$mini['mini_url']:$StoreAudit['logo'],
- 'signature'=>$mini['signature'],
- 'mini_nickname'=>!empty($mini['mini_nickname'])?$mini['mini_nickname']:$StoreAudit['name'],
- 'categories'=>!empty($mini['categories'])?json_decode($mini['categories'],true):[]
- ];
- if(!empty($mini)){//是否注册小程序
- if($mini['status'] == -1){ //小程序注册审核中
- $res = $this->openPlatform
- ->component
- ->getRegistrationStatus($mini['license_name'], $mini['legal_persona_account'], $mini['legal_persona_name']);
- return [
- 'code'=>0,
- 'msg'=>"小程序注册审核中",
-
- 'data'=>[
- 'mini_info'=>[
- 'id'=>$mini['id'],
- 'status'=>$mini['status'],
- 'license_name'=>$mini['license_name'],
- 'license_no'=>$mini['license_no'],
- 'code_type'=>$mini['code_type'],
- 'legal_persona_account'=>$mini['legal_persona_account'],
- 'legal_persona_name'=>$mini['legal_persona_name'],
- 'license_pic'=>$mini['license_pic'],
- ],
- 'alert_msg' => $this->getZnMsg($res),
- 'num'=>$res['errcode'] == 89250 ? 2 : 3, // 如果查询未找到该任务,重新提交
- 'progress'=>1,
- 'bind_store_id'=>$this->bind_store_id,
- ]
- ];
- }elseif($mini['status'] == 2){ //小程序注册审核失败
- return [
- 'code'=>0,
- 'msg'=>"小程序注册审核失败".$mini['msg'],
- 'data'=>[
- 'mini_info'=>[
- 'id'=>$mini['id'],
- 'status'=>$mini['status'],
- 'license_name'=>$mini['license_name'],
- 'license_no'=>$mini['license_no'],
- 'code_type'=>$mini['code_type'],
- 'legal_persona_account'=>$mini['legal_persona_account'],
- 'legal_persona_name'=>$mini['legal_persona_name'],
- 'license_pic'=>$mini['license_pic'],
- "msg"=>$mini['msg']
- ],
- 'alert_msg'=>"小程序注册审核失败".$mini['msg'],
- 'num'=>2,
- 'progress'=>1,
- 'bind_store_id'=>$this->bind_store_id,
- ]
- ];
- }elseif($mini['status'] == 0 || $mini['status'] == 1){//小程序注册成功
- // 支付进件状态
- if(!empty($MerchantInfo)){//判断进件是否提交资料
- if($MerchantInfo['status'] == 1){//判断审核状态
- $merchant = new Merchant();
- $res = $merchant->queryApplyment($MerchantInfo['applyment_id']);
-
- if ($res['applyment_state_msg']) {
- $alert_msg = $res['applyment_state_msg'];
- }
- if ($res['sign_url']) {
- $alert_url = $res['sign_url'];
- }
- return [
- 'code'=>0,
- 'msg'=>"进件材料审核中",
- 'data'=>[
- 'num'=>1,
- "progress"=>2,
- 'bind_store_id'=> $this->bind_store_id,
- "merchant_info"=> $merchant_info,
- 'alert_msg' => $alert_msg,
- 'alert_url' => isset($alert_url) ? $alert_url : ''
- ]
- ];
- }elseif($MerchantInfo['status'] == 2){
- return [
- 'code'=>0,
- 'msg'=>"进件材料审核失败".$MerchantInfo['refuse_desc'],
- 'data'=>[
- 'num'=>2,
- "progress"=>2,
- 'bind_store_id'=>$this->bind_store_id,
- "merchant_info"=>$merchant_info,
- 'msg'=>$MerchantInfo['refuse_desc'],
- 'alert_msg'=>"进件材料审核失败".$MerchantInfo['refuse_desc'],
- ]
- ];
- }elseif($MerchantInfo['status'] == 3){
- // 小程序完善资料
- if(empty($mini['mini_url'])||empty($mini['signature'])||empty($mini['mini_nickname'])||empty($mini['categories'])){
- return [
- 'code'=>0,
- 'msg'=>"小程序资料不全",
- 'data'=>[
- 'num'=>1,
- "progress"=>3,
- 'bind_store_id'=>$this->bind_store_id,
- 'mini_data'=>$mini_data,
- 'all_categories'=>$all_category,
- 'all_old_category' => $all_old_category
- ]
- ];
- }
- $form = new WechatThirdForm();
- $form->mini_id = $mini['id'];
- $res = $form->getNicknameAuditStatus();
- if (isset($res['status']) && $res['status'] == 3 && $mini['apply_name_status'] != 3) {
- $mini['apply_name_status'] = 3;
- }
- if($mini['apply_name_status'] == 2){
- return [
- 'code'=>0,
- 'msg'=>"小程序资料审核失败",
- 'data'=>[
- 'num'=>8,
- "progress"=>3,
- 'bind_store_id'=>$this->bind_store_id,
- 'mini_data'=>$mini_data,
- 'msg'=>$mini['apply_name_error'],
- 'all_categories'=>$all_category,
- 'alert_msg' => $mini['apply_name_error'],
- ]
- ];
- }
- if($mini['apply_name_status'] == 1){
- return [
- 'code'=>0,
- 'msg'=>"小程序资料开始审核",
- 'data'=>[
- 'num'=>7,
- "progress"=>3,
- 'bind_store_id'=>$this->bind_store_id,
- 'mini_data'=>$mini_data,
- 'all_categories'=>$all_category,
- 'alert_msg' => '小程序资料开始审核'
- ]
- ];
- }
- if($mini['mini_up'] == 5){ //判断是否完善资料
- $AggregateQrcode = AggregateQrcode::findOne(['store_id'=>$this->bind_store_id]);
- if(!empty($AggregateQrcode->wx_status)){
- return [
- 'code'=>0,
- 'msg'=>"完成",
- 'data'=>[
- 'num'=>0,
- 'bind_store_id'=>$this->bind_store_id,
- "progress"=>5,
- 'qrcode_id'=>$AggregateQrcode->id
- ]
- ];
- }else{
- return [
- 'code'=>0,
- 'msg'=>"没有绑定二维码",
- 'data'=>[
- 'num'=>1,
- 'bind_store_id'=>$this->bind_store_id,
- "progress"=>4,
- 'qrcode_id'=>$AggregateQrcode->id,
- 'alert_msg' => '没有绑定二维码'
- ]
- ];
- }
- }elseif($mini['mini_up'] == 4){
- return [
- 'code'=>0,
- 'msg'=>"小程序代码审核延迟",
- 'data'=>[
- 'num'=>4,
- 'bind_store_id'=>$this->bind_store_id,
- "progress"=>3,
- 'mini_data'=>$mini_data,
- ]
- ];
- }elseif($mini['mini_up'] == 2){
- return [
- 'code'=>0,
- 'msg'=>"小程序代码审核通过未发布",
- 'data'=>[
- 'num'=>6,
- 'bind_store_id'=>$this->bind_store_id,
- "progress"=>3,
- 'mini_data'=>$mini_data,
- ]
- ];
- }elseif($mini['mini_up'] == 3){
- return [
- 'code'=>0,
- 'msg'=>"小程序代码审核失败,".$mini['mini_up_error'],
- 'data'=>[
- 'msg'=>$mini['mini_up_error'],
- 'num'=>5,
- "progress"=>3,
- 'bind_store_id'=>$this->bind_store_id,
- 'mini_data'=>$mini_data,
- 'alert_msg' => $mini['mini_up_error']
- ]
- ];
- }elseif($mini['mini_up'] == 1){
- return [
- 'code'=>0,
- 'msg'=>"小程序代码审核中",
- 'data'=>[
- 'num'=>4,
- 'bind_store_id'=>$this->bind_store_id,
- "progress"=>3,
- 'mini_data'=>$mini_data,
- 'alert_msg' => '小程序代码审核中'
- ]
- ];
- }elseif($mini['mini_up'] == -1){
- return [
- 'code'=>0,
- 'msg'=>"小程序代码未审核",
- 'data'=>[
- 'num'=>3,
- 'bind_store_id'=>$this->bind_store_id,
- "progress"=>3,
- 'mini_data'=>$mini_data,
- ]
- ];
- }elseif($mini['mini_up'] == 0){
- return [
- 'code'=>0,
- 'msg'=>"小程序代码未上传",
- 'data'=>[
- 'num'=>2,
- 'bind_store_id'=>$this->bind_store_id,
- "progress"=>3,
- 'mini_data'=>$mini_data,
- ]
- ];
- }else{
- return [
- 'code'=>0,
- 'msg'=>"未知状态",
- 'data'=>[
- 'num'=>13,
- 'bind_store_id'=>$this->bind_store_id,
- "progress"=>3,
- 'mini_data'=>$mini_data,
- ]
- ];
- }
- }else{
- return [
- 'code'=>0,
- 'msg'=>"未提交进件资料",
- 'data'=>[
- 'num'=>3,
- "progress"=>2,
- 'bind_store_id'=>$this->bind_store_id,
- "merchant_info"=>$merchant_info,
- ]
- ];
- }
- }else{
- return [
- 'code'=>0,
- 'msg'=>"未提交进件资料",
- "data"=>[
- 'merchant_info'=>$merchant_info,
- 'bind_store_id'=>$this->bind_store_id,
- 'num'=>3,
- "progress"=>2,
- ]
- ];
- }
- }else{
- return [
- 'code'=>0,
- 'msg'=>"未知状态",
- 'data'=>[
- 'num'=>13,
- "progress"=>1
- ]
- ];
- }
- }else{
- return [
- 'code'=>0,
- 'msg'=>"小程序未注册",
- 'data'=>[
- 'num'=>1,
- "progress"=>1,
- "merchant_info"=>$merchant_info['subject_info'],
- 'mini_info'=>[
- 'license_name'=>$business_license_info['merchant_name'],
- 'license_no'=>$business_license_info['license_number'],
- 'code_type'=>1,
- 'legal_persona_name'=>$business_license_info['legal_person'],
- 'license_pic'=>$business_license_info['license_copy'],
- ],
- ]
- ];
- }
- }elseif($this->type=="ali"){
- //查询签约状态
- $mini = StoreAliMini::find()->alias('sam')->where(['sam.store_id'=>$this->bind_store_id,'sam.is_cancel'=>0])
- ->leftJoin(['mv'=>StoreAliMiniVersion::tableName()],'mv.mini_id = sam.id')
- ->orderBy('sam.id desc')
- ->select("sam.batch_status,sam.store_face_photo,mv.id m_id,mv.is_up,mv.is_submit,sam.id,sam.store_id,sam.category_data,sam.license_no,sam.license_pic,sam.app_name,sam.app_english_name,sam.app_slogan,sam.app_logo,sam.app_desc,sam.service_phone,sam.service_email,sam.mini_categoryIds,sam.license_date,sam.license_name,sam.category_name,sam.is_long_effective,sam.alipay_account,sam.legal_personal_name,sam.contact_name,sam.order_cancel")
- ->asArray()
- ->one();
- $mini_re_info = [
- "license_name"=>$mini['license_name'],
- "license_no"=>$mini['license_no'],
- "legal_persona_account"=>$mini['alipay_account'],
- "legal_persona_name"=>$mini['legal_personal_name'],
- "app_name"=>$mini['app_name'],
- "service_phone"=>$mini['service_phone'],
- "contact_name"=>$mini['contact_name'],
- "license_pic"=>$mini['license_pic'],
- ];
- $mini_categoryIds = [];
- if(!empty($mini['category_data'])){
- $mini_categoryIds = json_decode($mini['category_data'],true);
- }
- $mini_info = [
- "app_name"=>!empty($mini['app_name'])?$mini['app_name']:$StoreAudit['name'],
- "app_english_name"=>$mini['app_english_name'],
- "app_slogan"=>$mini['app_slogan'],
- "license_no"=>$mini['license_no'],
- "license_pic"=>$mini['license_pic'],
- "license_name"=>$mini['license_name'],
- "license_date"=>$mini['license_date'],
- "is_long_effective"=>$mini['is_long_effective'],
- "app_logo"=>!empty($mini['app_logo'])?$mini['app_logo']:$StoreAudit['logo'],
- "app_desc"=>$mini['app_desc'],
- "service_phone"=>$mini['service_phone'],
- "service_email"=>$mini['service_email'],
- "mini_categoryIds"=>$mini_categoryIds,
- ];
-
- if(empty($mini)){
- return [
- 'code'=>0,
- 'msg'=>"没有注册小程序",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'merchant_info'=>$merchant_info,
- 'progress'=>1,
- 'num'=>1,
- 'mini_info'=>[
- 'license_name'=>$business_license_info['merchant_name'],
- 'license_no'=>$business_license_info['license_number'],
- 'legal_persona_name'=>$business_license_info['legal_person'],
- 'license_pic'=>$business_license_info['license_copy'],
- "service_phone"=>$merchant_info['contact_info']['contact_name'],
- "contact_name"=> $merchant_info['contact_info']['mobile_phone'],
- "app_name"=>$StoreAudit['name']
- ]
- ]
- ];
- }else{//进度 提交 审核 () 完善信息
- // 获取当前审核状态
- // $res = (new AlipayThirdForm())->getMiniShenheStatus($mini['id']);
- // if (isset($res['status'])) {
- // }
- if(empty($mini['m_id'])){
- return [
- 'code'=>0,
- 'msg'=>"小程序注册待确认或签约审核中",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>1,
- 'num'=>2,
- 'mini_info'=>$mini_re_info
- ],
- ];
- }
- if($mini['order_cancel'] == 1){
- return [
- 'code'=>0,
- 'msg'=>"小程序注册已拒绝",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>1,
- 'num'=>3,
- 'mini_info'=>$mini_re_info
- ]
- ];
- }
-
- if($mini['is_submit'] == 0 && (
- empty($mini['app_name']) ||
- empty($mini['app_english_name']) ||
- empty($mini['app_slogan']) ||
- empty($mini['app_logo']) ||
- empty($mini['app_desc']) ||
- empty($mini['service_phone']) ||
- empty($mini['service_email']) ||
- empty($mini['mini_categoryIds'])
- )){
- return [
- 'code'=>0,
- 'msg'=>"小程序资料需要完善",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>2,
- 'num'=>1,
- 'mini_info'=>$mini_info,
- 'all_categories'=>$all_category
- ]
- ];
- }elseif($mini['is_submit'] == 0){
- return [
- 'code'=>0,
- 'msg'=>"小程序资料完善完成",//可以审核
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>2,
- 'num'=>2,
- 'mini_info'=>$mini_info
- ]
- ];
- }
- if($mini['is_submit'] == 1){
- return [
- 'code'=>0,
- 'msg'=>"小程序审核中",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>2,
- 'num'=>3,
- 'mini_info'=>$mini_info
- ]
- ];
- }elseif($mini['is_submit'] == 2){
- return [
- 'code'=>0,
- 'msg'=>"小程序审核通过",//可以发布
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>2,
- 'num'=>4,
- 'mini_info'=>$mini_info
- ]
- ];
- }elseif($mini['is_submit'] == 3){
- return [
- 'code'=>0,
- 'msg'=>"小程序审核失败",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>2,
- 'num'=>5,
- 'mini_info'=>$mini_info
- ]
- ];
- }elseif($mini['is_submit'] == 4){
- if($mini['batch_status'] == 0 || $mini['batch_status'] == 7){//没有创建事务
- return [
- 'code'=>0,
- 'msg'=>"需要创建事务",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>3,
- 'num'=>1
- ]
- ];
- }elseif($mini['batch_status'] == 1 || $mini['batch_status'] == 4){//创建事务成功
- return [
- 'code'=>0,
- 'msg'=>"需要签约当面付",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>3,
- 'num'=>2
- ]
- ];
- }elseif($mini['batch_status'] == 2){//签约当面付成功
- return [
- 'code'=>0,
- 'msg'=>"审核当面付",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>3,
- 'num'=>3
- ]
- ];
- }elseif($mini['batch_status'] == 3){//审核中
- return [
- 'code'=>0,
- 'msg'=>"审核中",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>3,
- 'num'=>4
- ]
- ];
- }elseif($mini['batch_status'] == 4){
- return [
- 'code'=>0,
- 'msg'=>"小程序签约已拒绝",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>3,
- 'num'=>5
- ]
- ];
- }elseif($mini['batch_status'] == 5){//等待商户确认
- return [
- 'code'=>0,
- 'msg'=>"等待商户确认",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>3,
- 'num'=>6
- ]
- ];
- }elseif($mini['batch_status'] == 6){//确认成功
- $AggregateQrcode = AggregateQrcode::find()->where(['and',['store_id'=>$this->bind_store_id],["<>",'ali_mini_id',""]])->one();
- if(!empty($AggregateQrcode->ali_status)){
- return [
- 'code'=>0,
- 'msg'=>"完成",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>5,
- 'num'=>1,
- 'qrcode_id'=>$AggregateQrcode->id
- ]
- ];
- }else{
- return [
- 'code'=>0,
- 'msg'=>"未绑定聚合码",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>4,
- 'num'=>1,
- 'qrcode_id'=>$AggregateQrcode->id
- ]
- ];
- }
- }elseif($mini['batch_status'] == 8){//审核失败
- return [
- 'code'=>0,
- 'msg'=>"审核失败",
- 'data'=>[
- 'bind_store_id'=>$this->bind_store_id,
- 'progress'=>3,
- 'num'=>7,
- 'store_face_photo'=>$mini['store_face_photo']
- ]
- ];
- }
- }
- }
- }else{
- return [
- 'code'=>0,
- 'msg'=>"未识别的操作系统",
- 'data'=>[
- 'num'=>13,
- "progress"=>1
- ]
- ];
- }
- }
- //小程序列表基础数据
- public function getUserInfo(){
- $saas_user_id = get_saas_user_id();
- //佣金
- //已到帐
- $query = SharingReceiver::find()->where(['user_id' => $saas_user_id, 'is_pay' => 1, 'from' => SharingReceiver::FROM_RECOMMEND,'is_delete'=>0])->andWhere(['like', 'order_no', 'ML']);//->sum('amount');
- $is_pay_money['all'] = $query->sum('amount')??'0';
- $is_pay_money['prev'] = $query->andWhere(['and',['<','created_at',strtotime(date('Y-m-d'))],['>','created_at',(strtotime(date('Y-m-d')) - 60*60*24)]])->sum('amount')??'0';
- //未到账
- $query = SharingReceiver::find()->where(['user_id' => $saas_user_id, 'is_pay' => 0, 'from' => SharingReceiver::FROM_RECOMMEND,'is_delete'=>0])->andWhere(['like', 'order_no', 'ML']);
- $no_pay_money['all'] = $query->sum('amount')??'0';
- $no_pay_money['prev'] = $query->andWhere(['and',['<','created_at',strtotime(date('Y-m-d'))],['>','created_at',(strtotime(date('Y-m-d')) - 60*60*24)]])->sum('amount')??'0';
- //总金额
- $query = SharingReceiver::find()->where(['user_id' => $saas_user_id, 'from' => SharingReceiver::FROM_RECOMMEND,'is_delete'=>0])->andWhere(['like', 'order_no', 'ML']);
- $all_pay_money['all'] = $query->sum('amount')??'0';
- $all_pay_money['prev'] = $query->andWhere(['and',['<','created_at',strtotime(date('Y-m-d'))],['>','created_at',(strtotime(date('Y-m-d')) - 60*60*24)]])->sum('amount')??'0';
- //分销订单数量
- $query = SharingReceiver::find()->where(['user_id' => $saas_user_id, 'from' => SharingReceiver::FROM_RECOMMEND])->andWhere(['like', 'order_no', 'ML']);
- $count['all'] = $query->count();
- $count['prev'] = $query->andWhere(['and',['<','created_at',strtotime(date('Y-m-d'))],['>','created_at',(strtotime(date('Y-m-d')) - 60*60*24)]])->count();
- //头像
- $avatar = get_saas_user()->avatar;
- //名称
- $name = get_saas_user()->name;
- //所属店铺
- $up_name = SaasUser::findOne(Admin::findOne(Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0])->admin_id)->saas_user_id)->name;
-
-
- //下级店铺数量
- $query = SaasStoreReferral::find()->alias('ssr')
- ->leftJoin(['s' => Store::tableName()], 's.id=ssr.store_id')
- ->andWhere(['ssr.referral_id' => $saas_user_id])->groupBy(['ssr.store_id'])->andWhere([
- '>',
- 's.id',
- 0
- ]);
- $sub_merchant_count['all'] = $query->count();
- $sub_merchant_count['prev'] = $query->andWhere(['and',['<','s.created_at',strtotime(date('Y-m-d'))],['>','s.created_at',(strtotime(date('Y-m-d')) - 60*60*24)]])->count();
- //(店铺待审核/待完善/待完成/待处理)
- $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
- $query = StoreAudit::find()->alias('sa')->leftJoin(['mi' => MerchantInfo::tableName()], 'mi.id=sa.merchant_info_id')->where(['sa.salesman_id' => $salesman->id, 'mi.is_delete' => 0]);
-
-
- //待审核
- $examineQuery = clone $query;
- $examineQuery->andWhere(['sa.status' => 0]);
- $examine['all'] = $examineQuery->count();
- $examine['prev'] = $examineQuery->andWhere(['OR',['and',['<','sa.created_at',strtotime(date('Y-m-d'))],['>','sa.created_at',(strtotime(date('Y-m-d')) - 60*60*24)]],['and',['<','sa.updated_at',strtotime(date('Y-m-d'))],['>','sa.updated_at',(strtotime(date('Y-m-d')) - 60*60*24)]]])->count();
- //待完善
- $repairQuery = clone $query;
- $repairQuery->andWhere(['and',['sa.status' => 1],['!=', 'mi.status', 3],['<>','mi.app_status','']]);
- $repair['all'] = $repairQuery->count();
- $repair['prev'] = $repairQuery->andWhere(['OR',['and',['<','sa.created_at',strtotime(date('Y-m-d'))],['>','sa.created_at',(strtotime(date('Y-m-d')) - 60*60*24)]],['and',['<','sa.updated_at',strtotime(date('Y-m-d'))],['>','sa.updated_at',(strtotime(date('Y-m-d')) - 60*60*24)]]])->count();
- //待完成
- $finishQuery = clone $query;
- $finishQuery->andWhere(['sa.status' => 1, 'mi.status' => 3,'mi.app_status'=>'12']);
- $finish['all'] = $finishQuery->count();
- $finish['prev'] = $finishQuery->andWhere(['OR',['and',['<','sa.created_at',strtotime(date('Y-m-d'))],['>','sa.created_at',(strtotime(date('Y-m-d')) - 60*60*24)]],['and',['<','sa.updated_at',strtotime(date('Y-m-d'))],['>','sa.updated_at',(strtotime(date('Y-m-d')) - 60*60*24)]]])->count();
- //待处理
- $query->andWhere(['OR',['sa.status' => 0],['and',['sa.status' => 1],['or',['!=', 'mi.status', 3],['<>','mi.app_status','']]]]);
- $handle_count['all'] = $query->count();
- $handle_count['prev'] = $query->andWhere(['OR',['and',['<','sa.created_at',strtotime(date('Y-m-d'))],['>','sa.created_at',(strtotime(date('Y-m-d')) - 60*60*24)]],['and',['<','sa.updated_at',strtotime(date('Y-m-d'))],['>','sa.updated_at',(strtotime(date('Y-m-d')) - 60*60*24)]]])->count();
- //展示微信审核失败信息
- $qrcode = AggregateQrcode::find()->where(['salesman_id'=>$salesman->id])->select('id,wx_mini_id,ali_mini_id,salesman_id,store_id')->asArray()->all();
- $mini = [];
- //拟定通知消息
- $notice = [];
-
-
- foreach($qrcode as $value){
- if(!empty($value['wx_mini_id'])){
- $data = StoreMini::find()->where(['AND',['id'=>$value['wx_mini_id']],['OR',['status'=>2,'mini_up'=>3]]])->select('id,store_id,msg,status,mini_up_error fail_reason,,mini_up,fail_time')->asArray()->one();
- $store = Store::find()->where(['id'=>$value['store_id']])->one();
- $data['name'] = !empty($store->name)?$store->name:'';
- $data['bind_store_id'] = $value['store_id'];
- $data['msg'] = "";
- if(!empty($data)){
- $data['msg'] = !empty($data['status'] == 2)?$data['msg']:$data['fail_reason'];
- }
- $data['type'] = 'weixin';
- if($data['status'] == 2){
- $notice[] = $store->name.'审核失败'.$data['msg'];
- }
- if($data['mini_up'] == 3){
- $notice[] = $store->name.'审核失败'.$data['fail_reason'];
- }
- $mini[] = $data;
- }
- if(!empty($value['ali_mini_id'])){
- $data = StoreAliMiniVersion::find()->where(['mini_id'=>$value['ali_mini_id'],'is_submit'=>3])->orderBy('id DESC')->select('id,fail_reason,is_submit mini_up,fail_time')->asArray()->one();
- $store = Store::find()->where(['id'=>$value['store_id']])->one();
- $data['name'] = !empty($store->name)?$store->name:'';
- $data['bind_store_id'] = $value['store_id'];
- $data['type'] = 'ali';
- $data['msg'] = "";
- if(!empty($data)){
- $data['msg'] = !empty($data['is_submit'] == 3)?$data['fail_reason']:'';
- }
- if($data['mini_up'] == 3){
- $notice[] = $store->name.'审核失败'.$data['ali']['fail_reason'];
- }
- $mini[] = $data;
- }
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'is_pay_money' => $is_pay_money,//已到账佣金
- 'no_pay_money' => $no_pay_money,//未到账佣金
- 'all_pay_money'=>$all_pay_money,//到账总金额
- 'count' => $count,//分销订单数量
- 'avatar' => $avatar,//头像
- 'name' => $name,//名称
- 'up_name' => $up_name ?: '',//总店
- 'sub_merchant_count'=>$sub_merchant_count, //下级店铺数量
- 'handle_count'=>$handle_count,//待处理数量
- 'mini'=>$mini,//有错误的小程序
- 'examine'=>$examine,//待审核数量
- 'repair'=>$repair,//待完成数量
- 'finish'=>$finish,//已完成数量
- 'notice'=>$notice,
- "id"=>$salesman->id
- ]
- ];
- }
- //获取顶部数量
- public function topNumber($query){
- //待审核
- $examine = clone $query;
- $examine = $examine->andWhere(['sa.status' => 0])->count();
- //待完善
- $repair = clone $query;
- $repair = $repair->andWhere(['and',['sa.status' => 1],['or',['!=', 'mi.status', 0],['<>','mi.app_status','']]])->count();
- //待完成
- $finish = clone $query;
- $finish = $finish->andWhere(['sa.status' => 1, 'mi.status' => 3,'mi.app_status'=>'12'])->count();
- return [
- 'examine'=>$examine,//待审核数量
- 'repair'=>$repair,//待完成数量
- 'finish'=>$finish,//已完成数量
- ];
- }
- //店铺列表
- public function merchantList(){
- ///分类数据
- $category = SaasCategory::find()->where(['is_delete'=>0])->orderBy('created_at DESC,sort DESC')->all();
- ///列表数据
- $page = $this->page;
- $status = $this->status;
- $sort = $this->sort;
- $category_id = $this->category_id;
- $type = $this->type == "weixin" ? 1 : 2;
- $saas_user_id = get_saas_user_id();
- $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
- $query = StoreAudit::find()->alias('sa')->leftJoin(['mi' => MerchantInfo::tableName()], 'mi.id=sa.merchant_info_id')->where(['sa.salesman_id' => $salesman->id, 'mi.is_delete' => 0]);
-
- $query->leftJoin(['sc'=>SaasCategory::tableName()],'sa.cat_id = sc.id')->andWhere(['sc.is_delete'=>0]);
- $res = $this->topNumber($query);
- if ($status == 0) {
- // 待审核
- $query->andWhere(['sa.status' => 0]);
- } else {
- // 审核通过
- $query->andWhere(['sa.status' => 1]);
- }
-
- if ($status == 1) {
- // 待完善
- // $query->andWhere(['sa.status' => 1]);
- // $query->andWhere([
- // 'OR',['!=', 'mi.status', 3],
- // ['!=','mi.app_status','']
- // ]);
- $query->andWhere([
- 'and',
- ['!=','mi.app_status',''],
- ['!=','mi.app_status','0']
- ]);
- }
- if ($status == 2) {
- // 已完成
- $query->andWhere([
- 'or',
- ['=','mi.app_status',''],
- ['=','mi.app_status','0']
- ]);
- }
- //排序
- if($sort == 0){
- $query->orderBy('sa.created_at DESC');
- }elseif($sort == 1 || $sort == 2){
- $query->orderBy('sa.updated_at DESC');
- }
- //分类
- if(!empty($category_id)){
- $query->andWhere(['sc.id'=>$category_id]);
- }
- //小程序类型
- // if(!empty($type) && $status != 0){
- // switch ($status){
- // case 2:
- // $query->andWhere(['NOT LIKE','mi.app_status',$type]);
- // break;
- // default:
- // $query->andWhere(['LIKE','mi.app_status',$type]);
- // break;
- // }
- // }
- //$query->select('sa.id,sa.saas_user_id,sa.cat_id,sa.salesman_id,sa.name,sa.logo,sa.mobile, mi.id merchant_info_id, mi.status merchant_status, mi.state state, mi.from from,mi.app_status,mi.bind_store_id store_id');
- //var_dump($query->createCommand()->getRawSql());die;
- $count = $query->count();
- $pagination = new Pagination(['totalCount' => $count, 'page' => $page - 1, 'pageSize' => 20]);
- $list = $query->select('sa.id,sa.saas_user_id,sa.cat_id,sa.salesman_id,sa.name,sa.logo,sa.mobile, mi.id merchant_info_id, mi.status merchant_status, mi.state state, mi.from from,mi.app_status,mi.bind_store_id store_id')->limit($pagination->limit)->offset($pagination->offset)->asArray()->all();
- foreach ($list as &$value) {
- $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
- $value['cat_name'] = SaasCategory::findOne($value['cat_id'])->name;
- $value['app_status'] = !empty($value['app_status'])?explode(',',$value['app_status']):[];
- $StoreSchedule = StoreSchedule::find()->where(['audit_id'=>$value['id']])->one();
- $value['merchant_info'] = [];
- $license_copy = json_decode($StoreSchedule['merchant_info'],true)['subject_info']['business_license_info']['license_copy'];
- if(!empty($license_copy)){
- array_push($value['merchant_info'],$license_copy);
- }
- //审核状态展示审核资料
- }
- $result = [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => $count,
- 'page_count' => $pagination->pageCount,
- 'list' => $list,
- 'examine'=>$res["examine"],//待审核数量
- 'repair'=>$res["repair"],//待完成数量
- 'finish'=>$res["finish"],//已完成数量
- 'category'=>$category
- ],
- ];
- return $result;
- }
- //审核店铺
- public function audit(){
- $id = $this->id;
- $status = $this->status;
- $audit = StoreAudit::findOne(['id' => $id, 'status' => 0]);
- if (!$audit) {
- return [
- 'code' => 1,
- 'msg' => '数据不存在'
- ];
- }
- $t = \Yii::$app->db->beginTransaction();
- $saas_user_id = get_saas_user_id();
- if ($status == 1) {
- // 自动创建admin账号
- $admin = new Admin();
- $admin->access_token = \Yii::$app->security->generateRandomString();
- $admin->username = $audit->name;
- // $admin->password = \Yii::$app->security->generatePasswordHash($audit->mobile);
- // 默认密码改为cyyvipcom 与后台添加商城统一
- $admin->password = \Yii::$app->security->generatePasswordHash('123456');
- $admin->mobile = $audit->mobile;
- $admin->name = $audit->name;
- $admin->type = 'store';
- if ($admin->save()) {
- $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
- $store = new Store();
- $store->admin_id = $admin->id;
- $store->logo = $audit->logo;
- $store->created_at = time();
- $store->name = $audit->name;
- $store->salesman_id = $salesman->id;
- $store->open_status = 0;
- $store->end_time = strtotime("+1 year");
- if ($store->save()) {
- $admin->type_id = $store->id;
- $admin->save();
- // // 绑定关系
- // $saas_store_referral = new SaasStoreReferral();
- // $saas_store_referral->store_id = $store->id;
- // $saas_store_referral->referral_id = $saas_user_id;
- // if (!$saas_store_referral->save()) {
- // $t->rollBack();
- // \Yii::error("绑定关系失败");
- // \Yii::error($saas_store_referral->errors);
- // return [
- // 'code' => 1,
- // 'msg' => "绑定关系失败"
- // ];
- // } else {
- //绑定二维码
- $AggregateQrcode = AggregateQrcode::find()->where(['audit_id'=>$id])->one();
- if(!empty($AggregateQrcode)){
- $AggregateQrcode->store_id = $store->id;
- $res = $AggregateQrcode->save();
- if(!$res){
- \Yii::error("聚合码绑定失败");
- \Yii::error($AggregateQrcode->errors);
- return [
- 'code' => 1,
- 'msg' => "聚合码绑定失败"
- ];
- }
- }
- //
- // $sales_admin = Admin::findOne($salesman->admin_id);
- // $sales_saas_user_id = $sales_admin->saas_user_id;
- // if ($sales_saas_user_id) {
- // // 代理商绑定
- // $saas_store_referral = new SaasStoreReferral();
- // $saas_store_referral->store_id = $store->id;
- // $saas_store_referral->referral_id = $sales_saas_user_id;
- // if (!$saas_store_referral->save()) {
- // $t->rollBack();
- // \Yii::error("代理商失败");
- // \Yii::error($saas_store_referral->errors);
- // return [
- // 'code' => 1,
- // 'msg' => "代理商绑定失败"
- // ];
- // }
- // }
- // }
- // 绑定上级关系
- if ($audit->saas_user_id) {
- // 绑定上级关系
- // if(!SaasStoreReferral::storeBindParent($audit->saas_user_id, $store->id)){
- // $t->rollBack();
- // \Yii::error("绑定上级关系失败");
- // throw new \Exception("绑定上级关系失败");
- // }
- }
- try {
- $merchant = new Merchant();
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- $merchant_info = new MerchantInfo();
- $merchant_info->store_id = get_store_id();
- $merchant_info->saas_user_id = $saas_user_id;
- $merchant_info->business_code = $merchant->getBusinessCode();
- $merchant_info->bind_store_id = $store->id;
- $merchant_info->app_status = "1,2";
- $merchant_info->from = 1;
- //保存进件数据
- $StoreSchedule = StoreSchedule::findOne(['audit_id'=>$id]);
- $StoreSchedule->store_id = $store->id;
- $res = $StoreSchedule->save();
- if(!$res){
- \Yii::error($StoreSchedule->errors);
- return [
- 'code' => 1,
- 'msg' => "保存数据信息失败"
- ];
- }
- if(!empty($StoreSchedule->merchant_info)){
- $store_merchant_info = json_decode($StoreSchedule->merchant_info,true);
- $merchant_info->contact_info = json_encode($store_merchant_info['contact_info']);
- $merchant_info->subject_info = json_encode($store_merchant_info['subject_info']);
- $merchant_info->business_info = json_encode($store_merchant_info['business_info']);
- $merchant_info->bank_account_info = json_encode($store_merchant_info['bank_account_info']);
- }
- if (!$merchant_info->save()) {
- $t->rollBack();
- \Yii::error($merchant_info->errors);
- return [
- 'code' => 1,
- 'msg' => "保存进件信息失败"
- ];
- } else {
- $audit->merchant_info_id = $merchant_info->id;
- if (!$audit->save()) {
- $t->rollBack();
- \Yii::error($audit->errors);
- return [
- 'code' => 1,
- 'msg' => "申请单修改失败"
- ];
- }
- }
- } else {
- $t->rollBack();
- \Yii::error($store->errors);
- return [
- 'code' => 1,
- 'msg' => "店铺新增失败"
- ];
- }
- } else {
- $t->rollBack();
- \Yii::error($admin->errors);
- return [
- 'code' => 1,
- 'msg' => "新增管理员失败"
- ];
- }
- }
- $audit->status = $status;
- if (!$audit->save()) {
- $t->rollBack();
- \Yii::error($audit->errors);
- return [
- 'code' => 1,
- 'msg' => "申请单修改失败。"
- ];
- } else {
- $t->commit();
- return [
- 'code' => 0,
- 'msg' => '操作成功'
- ];
- }
- }
- //获取进件信息
- public function getInfo(){
- $StoreSchedule = StoreSchedule::find()->where(['store_id'=>$this->bind_store_id])->select("merchant_info")->one();
- $merchant_info = [];
- if(!empty($StoreSchedule)){
- $merchant_info = json_decode($StoreSchedule->$StoreSchedule);
- }
- return $merchant_info;
- }
- /**
- * 生成业务编号
- * @return string
- */
- public function getBusinessCode()
- {
- return date('Ymd') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
- }
- }
|