| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\models;
- use app\models\Admin;
- use app\models\AggregateQrcode;
- use app\models\AggregateSaasQrcode;
- 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\SalesmanNewStore;
- 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\alliance\models\AlipayThirdForm;
- use app\modules\alliance\models\WechatThirdErrorMsgForm;
- use app\modules\alliance\models\WechatThirdForm;
- use app\utils\Notice\NoticeSend;
- 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 $business_model;
- 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', 'business_model'], "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;
- //下级店铺数量
- $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
- if (!$salesman) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '当前登录账户非业务员'
- ]);
- }
- $store_ids = SalesmanNewStore::find()->where(['salesman_saas_id' => $saas_user_id])
- ->andWhere(['>', 'store_id', 0])->select('store_id')->column();
- $query = Store::find()->where(['is_delete' => 0]);
- $query->andWhere([
- 'or',
- ['salesman_id' => $salesman->id],//修改店铺业务员时候修改的
- ['store_admin' => $saas_user_id],//修改店铺业务员时候修改的
- ['in', 'id', $store_ids]//业务员帮助店铺进件时候增加
- ]);
- $sub_merchant_count['all'] = $query->count();
- $sub_merchant_count['prev'] = $query->andWhere(['and',['<','created_at',strtotime(date('Y-m-d'))],['>','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 merchantNewList()
- {
- try {
- // $admin = Admin::findOne(['mobile' => get_saas_user()->mobile, 'type' => 'store', 'is_delete' => 0]);
- $query = Store::find()->where(['s.id' => $this->store_id])->alias('s')->leftJoin(['mi' => MerchantInfo::tableName()], 'mi.bind_store_id = s.id');
- $query->leftJoin(['sc'=>SaasCategory::tableName()],'s.category_id = sc.id')->andWhere(['s.is_delete' => 0, 'mi.is_delete' => 0]);
- $query->select('s.id store_id, s.category_id cat_id, s.name, s.logo, mi.id merchant_info_id, mi.status merchant_status, mi.state state, mi.from from,mi.app_status,mi.bind_store_id, s.business_model');
- $pagination = pagination_make($query);
- $list = $pagination['list'];
- 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);
- // }
- //审核状态展示审核资料
- }
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'row_count' => $pagination['totalCount'],
- 'page_count' => $pagination['pageNo'],
- 'list' => $list,
- 'examine'=>$res["examine"] ?? 0,//待审核数量
- 'repair'=>$res["repair"] ?? 0,//待完成数量
- 'finish'=>$res["finish"] ?? 0,//已完成数量
- ],
- ];
- } catch (\Exception $e) {
- return [
- 'code' => 0,
- 'msg' => $e->getMessage(),
- 'data' => []
- ];
- }
- }
- //店铺列表
- 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')
- ->leftJoin(['s' => Store::tableName()], 'mi.bind_store_id = s.id')
- ->where(['sa.salesman_id' => $salesman->id, 'mi.is_delete' => 0]);
- // $query = SaasStoreReferral::find()->alias('ssr')
- // ->leftJoin(['s' => Store::tableName()], 'ssr.store_id = s.id')
- // ->where(['ssr.referral_id' => $saas_user_id]);
- $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->leftJoin(['ssr' => SaasStoreReferral::tableName()]);
- // 审核通过
- $query->andWhere(['sa.status' => 1]);
- }
- if ($status == 1) {
- // 待完善
- // $query->andWhere(['sa.status' => 1]);
- // $query->andWhere([
- // 'OR',['!=', 'mi.status', 3],
- // ['!=','mi.app_status','']
- // ]);
- $query->andWhere([
- 'or',
- [
- 'and',
- ['!=','mi.app_status',''],
- ['!=','mi.app_status','0']
- ],
- 'isnull(mi.app_status)'
- ]);
- }
- 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, s.business_model')->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"] ?? 0,//待审核数量
- 'repair'=>$res["repair"] ?? 0,//待完成数量
- 'finish'=>$res["finish"] ?? 0,//已完成数量
- 'category'=>$category
- ],
- ];
- return $result;
- }
- //审核店铺
- public function audit(){
- $id = $this->id;
- $status = $this->status;
- $business_model = $this->business_model;
- $qrcode_id = $this->qrcode_id;
- $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) {
- //TODO 兼容
- // if (empty($qrcode_id) && !\Yii::$app->prod_is_dandianpu()) {
- // return [
- // 'code' => 1,
- // 'msg' => '请填写聚合码ID'
- // ];
- // }
- // if ((int)$business_model === 1) {
- // $AggregateQrcode = AggregateQrcode::findOne($qrcode_id);
- // } else {
- // $AggregateQrcode = AggregateSaasQrcode::findOne($qrcode_id);
- // }
- // if (empty($AggregateQrcode) && !\Yii::$app->prod_is_dandianpu()) {
- // return [
- // 'code' => 1,
- // 'msg' => '对应的聚合码不存在,请重试'
- // ];
- // }
- // 自动创建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';
- $file_name = \Yii::$app->runtimePath . '/logs/app_wechat.log';
- file_put_contents($file_name, "\r\n" . '[审核开始][' . date('Y-m-d H:i:s') . 1 . ']' , FILE_APPEND);
- 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->business_model = $business_model;
- $store->store_admin = $audit->saas_user_id;
- $store->name = $audit->name;
- $store->open_status = 0;
- $store->salesman_id = $salesman->id;
- $store->end_time = strtotime("+1 year");
- if ($store->save()) {
- file_put_contents($file_name, "\r\n" . '[审核开始][' . date('Y-m-d H:i:s') . 2 . ']' , FILE_APPEND);
- $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 {
- //绑定二维码
- if(!empty($AggregateQrcode)){
- $AggregateQrcode->store_id = $store->id;
- $AggregateQrcode->salesman_id = $salesman->id;
- $AggregateQrcode->admin_id = $salesman->admin_id;
- $AggregateQrcode->shop_bind_time = time();
- $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($salesman, $store->id)){
- // $t->rollBack();
- // \Yii::error("绑定上级关系失败");
- // throw new \Exception("绑定上级关系失败");
- // }
- }
- try {
- $merchant = new Merchant();
- } catch (\Exception $e) {
- return [
- 'code' => 1,
- 'msg' => $e->getMessage()
- ];
- }
- file_put_contents($file_name, "\r\n" . '[审核开始][' . date('Y-m-d H:i:s') . 3 . ']' , FILE_APPEND);
- $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;
- if (!$merchant_info->save()) {
- file_put_contents($file_name, "\r\n" . '[审核,保存merchant_info][' . date('Y-m-d H:i:s') . json_encode($merchant_info->errors) . ']' , FILE_APPEND);
- $t->rollBack();
- \Yii::error($merchant_info->errors);
- return [
- 'code' => 1,
- 'msg' => "保存进件信息失败"
- ];
- } else {
- $audit->merchant_info_id = $merchant_info->id;
- if (!$audit->save()) {
- file_put_contents($file_name, "\r\n" . '[审核,保存merchant_info][' . date('Y-m-d H:i:s') . json_encode($audit->errors) . ']' , FILE_APPEND);
- $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();
- //申请通过发送短信
- $res = NoticeSend::AgentExamine($audit->id, 2);
- if (isset($res['code']) && $res['code'] !== 0) {
- debug_log($res, 'sms.log');
- }
- return [
- 'code' => 0,
- 'msg' => '操作成功'
- ];
- }
- }
- //获取收款码
- public function getQrcode ()
- {
- $business_model = (int)$this->business_model;
- if (in_array($business_model, [1, 2, 3, 4])) {
- if ($business_model === 1) {
- $query = AggregateQrcode::find();
- } else {
- $query = AggregateSaasQrcode::find();
- }
- $qrcode = $query->where(['is_use' => 1, 'store_id' => 0])->select('id')->column();
- return [
- 'code' => 0,
- 'msg' => "SUCCESS",
- 'data' => $qrcode
- ];
- }
- return [
- 'code' => 0,
- 'msg' => "SUCCESS",
- 'data' => []
- ];
- }
- //获取进件信息
- 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));
- }
- }
|