NewSalesmanForm.php 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\alliance\models;
  8. use app\models\Admin;
  9. use app\models\AggregateQrcode;
  10. use app\models\AggregateSaasQrcode;
  11. use app\models\MerchantInfo;
  12. use app\models\Option;
  13. use app\models\SaasCategory;
  14. use app\models\SaasStoreReferral;
  15. use app\models\SaasUser;
  16. use app\models\Salesman;
  17. use app\models\SalesmanNewStore;
  18. use app\models\SharingReceiver;
  19. use app\models\Store;
  20. use app\models\StoreAliMini;
  21. use app\models\StoreAliMiniVersion;
  22. use app\models\StoreAudit;
  23. use app\models\StoreMini;
  24. use app\models\StoreSchedule;
  25. use app\modules\alliance\models\AlipayThirdForm;
  26. use app\modules\alliance\models\WechatThirdErrorMsgForm;
  27. use app\modules\alliance\models\WechatThirdForm;
  28. use app\utils\Notice\NoticeSend;
  29. use app\utils\WechatMerchant\Merchant;
  30. use yii\base\Model;
  31. use EasyWeChat\Factory;
  32. use yii\data\Pagination;
  33. class NewSalesmanForm extends Model
  34. {
  35. public $contact_info;
  36. public $subject_info;
  37. public $business_info;
  38. public $bank_account_info;
  39. public $mini_apply_info;
  40. public $type = 'weixin'; //'weixin'
  41. public $code;
  42. public $id;
  43. public $qrcode_id;
  44. public $page;
  45. public $status;
  46. public $sort;
  47. public $mini_id;
  48. public $category_id;
  49. public $merchant_info_id;
  50. public $store_id;
  51. public $bind_store_id;
  52. public $openPlatform;
  53. public $business_model;
  54. public function rules()
  55. {
  56. return [
  57. [["license_pic", "license_no", "license_name", "legal_personal_name", "contact_info", "subject_info", "business_info", "bank_account_info", "type","code","pay_fee"], 'string'],
  58. [["apply_id","id",'qrcode_id', "page", "status", "sort", "category_id",'store_id','merchant_info_id','bind_store_id','mini_id', 'business_model'], "integer"],
  59. [["mini_apply_info"], "array"]
  60. ];
  61. }
  62. public function __construct($config = [])
  63. {
  64. parent::__construct($config);
  65. $config = [
  66. 'app_id' => Option::get("platform_third_appid",0,'saas')['value'],
  67. 'secret' => Option::get("platform_third_secret",0,'saas')['value'],
  68. 'token' => Option::get("platform_token",0,'saas')['value'],
  69. 'aes_key' => Option::get("platform_encodingAesKey",0,'saas')['value']
  70. ];
  71. $this->store_id = !empty($this->store_id)?$this->store_id:get_store_id();
  72. $this->openPlatform = Factory::openPlatform($config);
  73. }
  74. //返回中文错误信息
  75. public function getZnMsg($result){
  76. $ErrorMsg = new WechatThirdErrorMsgForm();
  77. $arr = $ErrorMsg->getArray();
  78. $msg = !empty($arr[$result['errcode']])?$arr[$result['errcode']]:$result['errmsg'];
  79. return $msg;
  80. }
  81. //TODO 商户逻辑 start
  82. public function saveMerchant(){
  83. //保存商户信息
  84. $merchant_info = MerchantInfo::find()->where(['bind_store_id'=>$this->bind_store_id, 'is_delete' => 0])->one();
  85. $mini = StoreMini::find()->where(['store_id'=>$this->bind_store_id])->orderBy('id desc')->select('appid')->one();
  86. if(empty($merchant_info) || empty($mini->appid)){
  87. return [
  88. 'code' => 1,
  89. 'msg' =>"参数错误"
  90. ];
  91. }
  92. $Merchant = new Merchant();
  93. 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);
  94. }
  95. public function getMerchant(){
  96. $StoreSchedule = StoreSchedule::find()->where(['audit_id'=>$this->id])->select('merchant_info')->one();
  97. return [
  98. 'code'=>0,
  99. 'msg'=>"",
  100. 'data'=>$StoreSchedule
  101. ];
  102. }
  103. //申请小程序
  104. public function applyMini(){
  105. $saas_user_id = get_saas_user_id();
  106. $mini_apply_info = $this->mini_apply_info;
  107. $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  108. if($this->type == "weixin"){
  109. $form = new WechatThirdForm();
  110. $form->name = $mini_apply_info->license_name;
  111. $form->code = $mini_apply_info->license_no;
  112. $form->code_type = $mini_apply_info->code_type;
  113. $form->legal_persona_wechat = $mini_apply_info->legal_persona_account;
  114. $form->legal_persona_name = $mini_apply_info->legal_persona_name;
  115. $form->license_pic = $mini_apply_info->license_pic;
  116. $form->bind_store_id = $this->bind_store_id;
  117. $res = $form->fastRegisterMini();
  118. if($res['code'] === 0){
  119. if(!empty($this->bind_store_id)){
  120. $qrcode = AggregateQrcode::find()->where(['store_id'=>$this->bind_store_id])->one();
  121. if(!empty($qrcode)){
  122. $qrcode->wx_mini_id = $res['data'];
  123. $res = $qrcode->save();
  124. if($res){
  125. return [
  126. 'code'=>0,
  127. 'msg'=>"开始审核,绑定聚合码成功"
  128. ];
  129. }
  130. }
  131. }
  132. $res = [
  133. 'code'=>0,
  134. 'msg'=>"开始审核,聚合码未绑定"
  135. ];
  136. }
  137. }elseif($this->type == "ali"){
  138. $form = new AlipayThirdForm();
  139. $form->license_name = $mini_apply_info->license_name;
  140. $form->license_no = $mini_apply_info->license_no;
  141. $form->alipay_account = $mini_apply_info->legal_persona_account;
  142. $form->legal_personal_name = $mini_apply_info->legal_persona_name;
  143. $form->AppName = $mini_apply_info->app_name;
  144. $form->ServicePhone = $mini_apply_info->service_phone;
  145. $form->contact_name = $mini_apply_info->contact_name;
  146. $form->license_pic = $mini_apply_info->license_pic;
  147. $form->bind_store_id = $this->bind_store_id;
  148. $res = $form->isvCreateMini();
  149. if($res['code'] === 0){
  150. if(!empty($this->bind_store_id)){
  151. $qrcode = AggregateQrcode::find()->where(['store_id'=>$this->bind_store_id])->one();
  152. if(!empty($qrcode)){
  153. $qrcode->ali_mini_id = $res['id'];
  154. $res = $qrcode->save();
  155. if($res){
  156. return [
  157. 'code'=>0,
  158. 'msg'=>"开始审核,绑定聚合码成功"
  159. ];
  160. }
  161. }
  162. }
  163. $res = [
  164. 'code'=>0,
  165. 'msg'=>"开始审核,聚合码未绑定"
  166. ];
  167. }
  168. }else{
  169. $res = [
  170. 'code'=>1,
  171. 'msg'=>"未知的申请方式"
  172. ];
  173. }
  174. return $res;
  175. }
  176. //绑定收款码
  177. public function bindPayQrcode(){
  178. $bind_store_id = !empty($this->bind_store_id) ? $this->bind_store_id : get_store_id();
  179. if (!empty($this->bind_store_id)){
  180. $saas_user_id = get_saas_user_id();
  181. $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  182. $AggregateQrcode = AggregateQrcode::find()->where([
  183. 'or',
  184. ['id' => $this->qrcode_id],
  185. ['store_id' => $bind_store_id]
  186. ])->one();
  187. } else{
  188. $AggregateQrcode = AggregateQrcode::find()->where(['store_id' => $bind_store_id])->one();
  189. if(empty($AggregateQrcode->salesman_id)){
  190. return [
  191. 'code'=>1,
  192. 'msg'=>"请绑定业务员"
  193. ];
  194. }
  195. $salesman = Salesman::findOne($AggregateQrcode->salesman_id);
  196. }
  197. // \Yii::error(json_encode($AggregateQrcode));
  198. if (empty($AggregateQrcode)){
  199. return [
  200. 'code'=>1,
  201. 'msg'=>"聚合码不存在"
  202. ];
  203. }
  204. if (empty($AggregateQrcode->ali_status) || empty($AggregateQrcode->wx_status)){
  205. if ($this->type == "weixin" || empty($this->type)){
  206. $form = StoreMini::find()->where(['store_id'=>$bind_store_id])->orderBy('id desc')->select('id,appid')->asArray()->one();
  207. $mini_id = !empty($this->mini_id)?$this->mini_id:$form['id'];
  208. $AggregateQrcode->wx_mini_id = $mini_id;
  209. } elseif($this->type == "ali"){
  210. $form = StoreAliMini::find()->where(['store_id'=>$bind_store_id])->orderBy('id desc')->select('id,auth_app_id appid')->asArray()->one();
  211. $mini_id = !empty($this->mini_id)?$this->mini_id:$form['id'];
  212. $AggregateQrcode->ali_mini_id = $mini_id;
  213. }
  214. if (empty($form['appid'])){
  215. return [
  216. 'code'=>1,
  217. 'msg'=>"没有找到任何的小程序或小程序未创建完成"
  218. ];
  219. }
  220. $AggregateQrcode->store_id = $bind_store_id;
  221. $AggregateQrcode->mini_time = time();
  222. if (empty($AggregateQrcode->salesman_id)){
  223. $AggregateQrcode->salesman_id = $salesman->id;
  224. $AggregateQrcode->admin_id = $salesman->admin_id;
  225. }
  226. $res = $AggregateQrcode->save();
  227. if ($res){
  228. if ($this->type == "ali"){
  229. $form = new AlipayThirdForm();
  230. $res = $form->bindQrcode($AggregateQrcode->ali_mini_id);
  231. if ($res['code'] != 0){
  232. return [
  233. 'code'=>1,
  234. 'msg'=>'绑定失败'
  235. ];
  236. }
  237. $MerchantInfo = MerchantInfo::find()->where([ 'bind_store_id' => $bind_store_id, 'is_delete' => 0])->orderBy('id desc')->one();
  238. if (!empty($MerchantInfo) && !empty($this->bind_store_id)){
  239. $str = $MerchantInfo->app_status;
  240. $str_arr = explode(',', $str);
  241. // 判断当前数组是否包含1
  242. if (in_array(2, $str_arr)) {
  243. $string = count($str_arr) > 1 ? '1' : '0';
  244. $MerchantInfo->app_status = $string;
  245. }
  246. if (!$MerchantInfo->save()){
  247. return [
  248. 'code'=>1,
  249. 'msg'=>json_encode($MerchantInfo->errors)
  250. ];
  251. }
  252. }
  253. return [
  254. 'code'=>0,
  255. 'msg'=>"绑定成功"
  256. ];
  257. }elseif($this->type == "weixin" || empty($this->type)){
  258. $wechat = new WechatThirdForm();
  259. $wechat->bind_store_id = $bind_store_id;
  260. $res = $wechat->downQrcodeRules($form['id'],$form['appid']);
  261. if($res['code'] === 0){
  262. $MerchantInfo = MerchantInfo::find()->where(['bind_store_id' => $bind_store_id, 'is_delete' => 0])->orderBy('id desc')->one();
  263. if(!empty($MerchantInfo) && !empty($this->bind_store_id)){
  264. $str = $MerchantInfo->app_status;
  265. $str_arr = explode(',', $str);
  266. // 判断当前数组是否包含1
  267. if(in_array(1, $str_arr)) {
  268. $string = count($str_arr) > 1 ? '2' : '0';
  269. $MerchantInfo->app_status = $string;
  270. }
  271. if(!$MerchantInfo->save()){
  272. return [
  273. 'code'=>1,
  274. 'msg'=>json_encode($MerchantInfo->errors)
  275. ];
  276. }
  277. }
  278. return [
  279. 'code'=>0,
  280. 'msg'=>"绑定成功"
  281. ];
  282. }else{
  283. return [
  284. 'code'=>1,
  285. 'msg'=>$res['msg']
  286. ];
  287. }
  288. }else{
  289. return [
  290. 'code'=>1,
  291. 'msg'=>'使用未知的系统'
  292. ];
  293. }
  294. }else{
  295. return [
  296. 'code'=>1,
  297. 'msg'=>'绑定失败'
  298. ];
  299. }
  300. }else{
  301. return [
  302. 'code'=>1,
  303. 'msg'=>'已经绑定完成,请勿重复绑定'
  304. ];
  305. }
  306. }
  307. //获取进度信息
  308. public function getProgress(){//注册小程序-进件状态-小程序完善状态-绑定二维码状态
  309. if(empty($this->bind_store_id)){
  310. return [
  311. 'code'=>1,
  312. 'msg'=>"参数错误",
  313. 'data'=>[
  314. 'num'=>2,
  315. 'progress'=>1
  316. ]
  317. ];
  318. }
  319. $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();
  320. $StoreSchedule = StoreSchedule::find()->where(['store_id'=>$this->bind_store_id])->one();
  321. $StoreAudit = StoreAudit::find()->where(['merchant_info_id'=>$MerchantInfo['id']])->select("name,logo")->asArray()->one();
  322. $form = new WechatThirdForm();
  323. $form->bind_store_id = $this->bind_store_id;
  324. $all_categories = $form->getAllCategories();
  325. $all_category = [];
  326. $all_old_category = [];
  327. if($all_categories['code'] === 0){
  328. $all_old_category = $all_categories['old_data'];
  329. $all_category = $all_categories['data'][0]['children'];
  330. }
  331. if($this->type == 'ali'){
  332. $form = new AlipayThirdForm();
  333. $form->bind_store_id = $this->bind_store_id;
  334. $all_categories = $form->getCategoryList();
  335. if($all_categories['code'] === 0){
  336. $all_category = $all_categories['data'];
  337. }
  338. }
  339. $merchant_info = [];
  340. if(!empty($StoreSchedule->merchant_info)){
  341. $merchant_info = json_decode($StoreSchedule->merchant_info,true);
  342. $business_license_info = $merchant_info['subject_info']['business_license_info'];
  343. }
  344. if($MerchantInfo['status'] > 0){
  345. $merchant_info = $MerchantInfo;
  346. $merchant_info['subject_info'] = !empty($merchant_info['subject_info'])?json_decode($merchant_info['subject_info'],true):[];
  347. $business_license_info = $merchant_info['subject_info']['business_license_info'];
  348. $merchant_info['business_info'] = !empty($merchant_info['business_info'])?json_decode($merchant_info['business_info'],true):[];
  349. $merchant_info['settlement_info'] = !empty($merchant_info['settlement_info'])?json_decode($merchant_info['settlement_info'],true):[];
  350. $merchant_info['bank_account_info'] = !empty($merchant_info['bank_account_info'])?json_decode($merchant_info['bank_account_info'],true):[];
  351. $merchant_info['contact_info'] = !empty($merchant_info['contact_info'])?json_decode($merchant_info['contact_info'],true):[];
  352. }
  353. // \Yii::error($merchant_info);
  354. if($this->type == "weixin"){
  355. $mini = StoreMini::find()->where(['store_id'=>$this->bind_store_id])
  356. ->orderBy('id desc')
  357. ->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')
  358. ->asArray()->one();
  359. $mini_data = [
  360. 'mini_url'=>!empty($mini['mini_url'])?$mini['mini_url']:$StoreAudit['logo'],
  361. 'signature'=>$mini['signature'],
  362. 'mini_nickname'=>!empty($mini['mini_nickname'])?$mini['mini_nickname']:$StoreAudit['name'],
  363. 'categories'=>!empty($mini['categories'])?json_decode($mini['categories'],true):[]
  364. ];
  365. if(!empty($mini)){//是否注册小程序
  366. if($mini['status'] == -1){ //小程序注册审核中
  367. $res = $this->openPlatform
  368. ->component
  369. ->getRegistrationStatus($mini['license_name'], $mini['legal_persona_account'], $mini['legal_persona_name']);
  370. return [
  371. 'code'=>0,
  372. 'msg'=>"小程序注册审核中",
  373. 'data'=>[
  374. 'mini_info'=>[
  375. 'id'=>$mini['id'],
  376. 'status'=>$mini['status'],
  377. 'license_name'=>$mini['license_name'],
  378. 'license_no'=>$mini['license_no'],
  379. 'code_type'=>$mini['code_type'],
  380. 'legal_persona_account'=>$mini['legal_persona_account'],
  381. 'legal_persona_name'=>$mini['legal_persona_name'],
  382. 'license_pic'=>$mini['license_pic'],
  383. ],
  384. 'alert_msg' => $this->getZnMsg($res),
  385. 'num'=>$res['errcode'] == 89250 ? 2 : 3, // 如果查询未找到该任务,重新提交
  386. 'progress'=>1,
  387. 'bind_store_id'=>$this->bind_store_id,
  388. ]
  389. ];
  390. }elseif($mini['status'] == 2){ //小程序注册审核失败
  391. return [
  392. 'code'=>0,
  393. 'msg'=>"小程序注册审核失败".$mini['msg'],
  394. 'data'=>[
  395. 'mini_info'=>[
  396. 'id'=>$mini['id'],
  397. 'status'=>$mini['status'],
  398. 'license_name'=>$mini['license_name'],
  399. 'license_no'=>$mini['license_no'],
  400. 'code_type'=>$mini['code_type'],
  401. 'legal_persona_account'=>$mini['legal_persona_account'],
  402. 'legal_persona_name'=>$mini['legal_persona_name'],
  403. 'license_pic'=>$mini['license_pic'],
  404. "msg"=>$mini['msg']
  405. ],
  406. 'alert_msg'=>"小程序注册审核失败".$mini['msg'],
  407. 'num'=>2,
  408. 'progress'=>1,
  409. 'bind_store_id'=>$this->bind_store_id,
  410. ]
  411. ];
  412. }elseif($mini['status'] == 0 || $mini['status'] == 1){//小程序注册成功
  413. // 支付进件状态
  414. if(!empty($MerchantInfo)){//判断进件是否提交资料
  415. if($MerchantInfo['status'] == 1){//判断审核状态
  416. $merchant = new Merchant();
  417. $res = $merchant->queryApplyment($MerchantInfo['applyment_id']);
  418. if ($res['applyment_state_msg']) {
  419. $alert_msg = $res['applyment_state_msg'];
  420. }
  421. if ($res['sign_url']) {
  422. $alert_url = $res['sign_url'];
  423. }
  424. return [
  425. 'code'=>0,
  426. 'msg'=>"进件材料审核中",
  427. 'data'=>[
  428. 'num'=>1,
  429. "progress"=>2,
  430. 'bind_store_id'=> $this->bind_store_id,
  431. "merchant_info"=> $merchant_info,
  432. 'alert_msg' => $alert_msg,
  433. 'alert_url' => isset($alert_url) ? $alert_url : ''
  434. ]
  435. ];
  436. }elseif($MerchantInfo['status'] == 2){
  437. return [
  438. 'code'=>0,
  439. 'msg'=>"进件材料审核失败".$MerchantInfo['refuse_desc'],
  440. 'data'=>[
  441. 'num'=>2,
  442. "progress"=>2,
  443. 'bind_store_id'=>$this->bind_store_id,
  444. "merchant_info"=>$merchant_info,
  445. 'msg'=>$MerchantInfo['refuse_desc'],
  446. 'alert_msg'=>"进件材料审核失败".$MerchantInfo['refuse_desc'],
  447. ]
  448. ];
  449. }elseif($MerchantInfo['status'] == 3){
  450. // 小程序完善资料
  451. if(empty($mini['mini_url'])||empty($mini['signature'])||empty($mini['mini_nickname'])||empty($mini['categories'])){
  452. return [
  453. 'code'=>0,
  454. 'msg'=>"小程序资料不全",
  455. 'data'=>[
  456. 'num'=>1,
  457. "progress"=>3,
  458. 'bind_store_id'=>$this->bind_store_id,
  459. 'mini_data'=>$mini_data,
  460. 'all_categories'=>$all_category,
  461. 'all_old_category' => $all_old_category
  462. ]
  463. ];
  464. }
  465. $form = new WechatThirdForm();
  466. $form->mini_id = $mini['id'];
  467. $res = $form->getNicknameAuditStatus();
  468. if (isset($res['status']) && $res['status'] == 3 && $mini['apply_name_status'] != 3) {
  469. $mini['apply_name_status'] = 3;
  470. }
  471. if($mini['apply_name_status'] == 2){
  472. return [
  473. 'code'=>0,
  474. 'msg'=>"小程序资料审核失败",
  475. 'data'=>[
  476. 'num'=>8,
  477. "progress"=>3,
  478. 'bind_store_id'=>$this->bind_store_id,
  479. 'mini_data'=>$mini_data,
  480. 'msg'=>$mini['apply_name_error'],
  481. 'all_categories'=>$all_category,
  482. 'alert_msg' => $mini['apply_name_error'],
  483. ]
  484. ];
  485. }
  486. if($mini['apply_name_status'] == 1){
  487. return [
  488. 'code'=>0,
  489. 'msg'=>"小程序资料开始审核",
  490. 'data'=>[
  491. 'num'=>7,
  492. "progress"=>3,
  493. 'bind_store_id'=>$this->bind_store_id,
  494. 'mini_data'=>$mini_data,
  495. 'all_categories'=>$all_category,
  496. 'alert_msg' => '小程序资料开始审核'
  497. ]
  498. ];
  499. }
  500. if($mini['mini_up'] == 5){ //判断是否完善资料
  501. $AggregateQrcode = AggregateQrcode::findOne(['store_id'=>$this->bind_store_id]);
  502. if(!empty($AggregateQrcode->wx_status)){
  503. return [
  504. 'code'=>0,
  505. 'msg'=>"完成",
  506. 'data'=>[
  507. 'num'=>0,
  508. 'bind_store_id'=>$this->bind_store_id,
  509. "progress"=>5,
  510. 'qrcode_id'=>$AggregateQrcode->id
  511. ]
  512. ];
  513. }else{
  514. return [
  515. 'code'=>0,
  516. 'msg'=>"没有绑定二维码",
  517. 'data'=>[
  518. 'num'=>1,
  519. 'bind_store_id'=>$this->bind_store_id,
  520. "progress"=>4,
  521. 'qrcode_id'=>$AggregateQrcode->id,
  522. 'alert_msg' => '没有绑定二维码'
  523. ]
  524. ];
  525. }
  526. }elseif($mini['mini_up'] == 4){
  527. return [
  528. 'code'=>0,
  529. 'msg'=>"小程序代码审核延迟",
  530. 'data'=>[
  531. 'num'=>4,
  532. 'bind_store_id'=>$this->bind_store_id,
  533. "progress"=>3,
  534. 'mini_data'=>$mini_data,
  535. ]
  536. ];
  537. }elseif($mini['mini_up'] == 2){
  538. return [
  539. 'code'=>0,
  540. 'msg'=>"小程序代码审核通过未发布",
  541. 'data'=>[
  542. 'num'=>6,
  543. 'bind_store_id'=>$this->bind_store_id,
  544. "progress"=>3,
  545. 'mini_data'=>$mini_data,
  546. ]
  547. ];
  548. }elseif($mini['mini_up'] == 3){
  549. return [
  550. 'code'=>0,
  551. 'msg'=>"小程序代码审核失败,".$mini['mini_up_error'],
  552. 'data'=>[
  553. 'msg'=>$mini['mini_up_error'],
  554. 'num'=>5,
  555. "progress"=>3,
  556. 'bind_store_id'=>$this->bind_store_id,
  557. 'mini_data'=>$mini_data,
  558. 'alert_msg' => $mini['mini_up_error']
  559. ]
  560. ];
  561. }elseif($mini['mini_up'] == 1){
  562. return [
  563. 'code'=>0,
  564. 'msg'=>"小程序代码审核中",
  565. 'data'=>[
  566. 'num'=>4,
  567. 'bind_store_id'=>$this->bind_store_id,
  568. "progress"=>3,
  569. 'mini_data'=>$mini_data,
  570. 'alert_msg' => '小程序代码审核中'
  571. ]
  572. ];
  573. }elseif($mini['mini_up'] == -1){
  574. return [
  575. 'code'=>0,
  576. 'msg'=>"小程序代码未审核",
  577. 'data'=>[
  578. 'num'=>3,
  579. 'bind_store_id'=>$this->bind_store_id,
  580. "progress"=>3,
  581. 'mini_data'=>$mini_data,
  582. ]
  583. ];
  584. }elseif($mini['mini_up'] == 0){
  585. return [
  586. 'code'=>0,
  587. 'msg'=>"小程序代码未上传",
  588. 'data'=>[
  589. 'num'=>2,
  590. 'bind_store_id'=>$this->bind_store_id,
  591. "progress"=>3,
  592. 'mini_data'=>$mini_data,
  593. ]
  594. ];
  595. }else{
  596. return [
  597. 'code'=>0,
  598. 'msg'=>"未知状态",
  599. 'data'=>[
  600. 'num'=>13,
  601. 'bind_store_id'=>$this->bind_store_id,
  602. "progress"=>3,
  603. 'mini_data'=>$mini_data,
  604. ]
  605. ];
  606. }
  607. }else{
  608. return [
  609. 'code'=>0,
  610. 'msg'=>"未提交进件资料",
  611. 'data'=>[
  612. 'num'=>3,
  613. "progress"=>2,
  614. 'bind_store_id'=>$this->bind_store_id,
  615. "merchant_info"=>$merchant_info,
  616. ]
  617. ];
  618. }
  619. }else{
  620. return [
  621. 'code'=>0,
  622. 'msg'=>"未提交进件资料",
  623. "data"=>[
  624. 'merchant_info'=>$merchant_info,
  625. 'bind_store_id'=>$this->bind_store_id,
  626. 'num'=>3,
  627. "progress"=>2,
  628. ]
  629. ];
  630. }
  631. }else{
  632. return [
  633. 'code'=>0,
  634. 'msg'=>"未知状态",
  635. 'data'=>[
  636. 'num'=>13,
  637. "progress"=>1
  638. ]
  639. ];
  640. }
  641. }else{
  642. return [
  643. 'code'=>0,
  644. 'msg'=>"小程序未注册",
  645. 'data'=>[
  646. 'num'=>1,
  647. "progress"=>1,
  648. "merchant_info"=>$merchant_info['subject_info'],
  649. 'mini_info'=>[
  650. 'license_name'=>$business_license_info['merchant_name'],
  651. 'license_no'=>$business_license_info['license_number'],
  652. 'code_type'=>1,
  653. 'legal_persona_name'=>$business_license_info['legal_person'],
  654. 'license_pic'=>$business_license_info['license_copy'],
  655. ],
  656. ]
  657. ];
  658. }
  659. }elseif($this->type=="ali"){
  660. //查询签约状态
  661. $mini = StoreAliMini::find()->alias('sam')->where(['sam.store_id'=>$this->bind_store_id,'sam.is_cancel'=>0])
  662. ->leftJoin(['mv'=>StoreAliMiniVersion::tableName()],'mv.mini_id = sam.id')
  663. ->orderBy('sam.id desc')
  664. ->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")
  665. ->asArray()
  666. ->one();
  667. $mini_re_info = [
  668. "license_name"=>$mini['license_name'],
  669. "license_no"=>$mini['license_no'],
  670. "legal_persona_account"=>$mini['alipay_account'],
  671. "legal_persona_name"=>$mini['legal_personal_name'],
  672. "app_name"=>$mini['app_name'],
  673. "service_phone"=>$mini['service_phone'],
  674. "contact_name"=>$mini['contact_name'],
  675. "license_pic"=>$mini['license_pic'],
  676. ];
  677. $mini_categoryIds = [];
  678. if(!empty($mini['category_data'])){
  679. $mini_categoryIds = json_decode($mini['category_data'],true);
  680. }
  681. $mini_info = [
  682. "app_name"=>!empty($mini['app_name'])?$mini['app_name']:$StoreAudit['name'],
  683. "app_english_name"=>$mini['app_english_name'],
  684. "app_slogan"=>$mini['app_slogan'],
  685. "license_no"=>$mini['license_no'],
  686. "license_pic"=>$mini['license_pic'],
  687. "license_name"=>$mini['license_name'],
  688. "license_date"=>$mini['license_date'],
  689. "is_long_effective"=>$mini['is_long_effective'],
  690. "app_logo"=>!empty($mini['app_logo'])?$mini['app_logo']:$StoreAudit['logo'],
  691. "app_desc"=>$mini['app_desc'],
  692. "service_phone"=>$mini['service_phone'],
  693. "service_email"=>$mini['service_email'],
  694. "mini_categoryIds"=>$mini_categoryIds,
  695. ];
  696. if(empty($mini)){
  697. return [
  698. 'code'=>0,
  699. 'msg'=>"没有注册小程序",
  700. 'data'=>[
  701. 'bind_store_id'=>$this->bind_store_id,
  702. 'merchant_info'=>$merchant_info,
  703. 'progress'=>1,
  704. 'num'=>1,
  705. 'mini_info'=>[
  706. 'license_name'=>$business_license_info['merchant_name'],
  707. 'license_no'=>$business_license_info['license_number'],
  708. 'legal_persona_name'=>$business_license_info['legal_person'],
  709. 'license_pic'=>$business_license_info['license_copy'],
  710. "service_phone"=>$merchant_info['contact_info']['contact_name'],
  711. "contact_name"=> $merchant_info['contact_info']['mobile_phone'],
  712. "app_name"=>$StoreAudit['name']
  713. ]
  714. ]
  715. ];
  716. }else{//进度 提交 审核 () 完善信息
  717. // 获取当前审核状态
  718. // $res = (new AlipayThirdForm())->getMiniShenheStatus($mini['id']);
  719. // if (isset($res['status'])) {
  720. // }
  721. if(empty($mini['m_id'])){
  722. return [
  723. 'code'=>0,
  724. 'msg'=>"小程序注册待确认或签约审核中",
  725. 'data'=>[
  726. 'bind_store_id'=>$this->bind_store_id,
  727. 'progress'=>1,
  728. 'num'=>2,
  729. 'mini_info'=>$mini_re_info
  730. ],
  731. ];
  732. }
  733. if($mini['order_cancel'] == 1){
  734. return [
  735. 'code'=>0,
  736. 'msg'=>"小程序注册已拒绝",
  737. 'data'=>[
  738. 'bind_store_id'=>$this->bind_store_id,
  739. 'progress'=>1,
  740. 'num'=>3,
  741. 'mini_info'=>$mini_re_info
  742. ]
  743. ];
  744. }
  745. if($mini['is_submit'] == 0 && (
  746. empty($mini['app_name']) ||
  747. empty($mini['app_english_name']) ||
  748. empty($mini['app_slogan']) ||
  749. empty($mini['app_logo']) ||
  750. empty($mini['app_desc']) ||
  751. empty($mini['service_phone']) ||
  752. empty($mini['service_email']) ||
  753. empty($mini['mini_categoryIds'])
  754. )){
  755. return [
  756. 'code'=>0,
  757. 'msg'=>"小程序资料需要完善",
  758. 'data'=>[
  759. 'bind_store_id'=>$this->bind_store_id,
  760. 'progress'=>2,
  761. 'num'=>1,
  762. 'mini_info'=>$mini_info,
  763. 'all_categories'=>$all_category
  764. ]
  765. ];
  766. }elseif($mini['is_submit'] == 0){
  767. return [
  768. 'code'=>0,
  769. 'msg'=>"小程序资料完善完成",//可以审核
  770. 'data'=>[
  771. 'bind_store_id'=>$this->bind_store_id,
  772. 'progress'=>2,
  773. 'num'=>2,
  774. 'mini_info'=>$mini_info
  775. ]
  776. ];
  777. }
  778. if($mini['is_submit'] == 1){
  779. return [
  780. 'code'=>0,
  781. 'msg'=>"小程序审核中",
  782. 'data'=>[
  783. 'bind_store_id'=>$this->bind_store_id,
  784. 'progress'=>2,
  785. 'num'=>3,
  786. 'mini_info'=>$mini_info
  787. ]
  788. ];
  789. }elseif($mini['is_submit'] == 2){
  790. return [
  791. 'code'=>0,
  792. 'msg'=>"小程序审核通过",//可以发布
  793. 'data'=>[
  794. 'bind_store_id'=>$this->bind_store_id,
  795. 'progress'=>2,
  796. 'num'=>4,
  797. 'mini_info'=>$mini_info
  798. ]
  799. ];
  800. }elseif($mini['is_submit'] == 3){
  801. return [
  802. 'code'=>0,
  803. 'msg'=>"小程序审核失败",
  804. 'data'=>[
  805. 'bind_store_id'=>$this->bind_store_id,
  806. 'progress'=>2,
  807. 'num'=>5,
  808. 'mini_info'=>$mini_info
  809. ]
  810. ];
  811. }elseif($mini['is_submit'] == 4){
  812. if($mini['batch_status'] == 0 || $mini['batch_status'] == 7){//没有创建事务
  813. return [
  814. 'code'=>0,
  815. 'msg'=>"需要创建事务",
  816. 'data'=>[
  817. 'bind_store_id'=>$this->bind_store_id,
  818. 'progress'=>3,
  819. 'num'=>1
  820. ]
  821. ];
  822. }elseif($mini['batch_status'] == 1 || $mini['batch_status'] == 4){//创建事务成功
  823. return [
  824. 'code'=>0,
  825. 'msg'=>"需要签约当面付",
  826. 'data'=>[
  827. 'bind_store_id'=>$this->bind_store_id,
  828. 'progress'=>3,
  829. 'num'=>2
  830. ]
  831. ];
  832. }elseif($mini['batch_status'] == 2){//签约当面付成功
  833. return [
  834. 'code'=>0,
  835. 'msg'=>"审核当面付",
  836. 'data'=>[
  837. 'bind_store_id'=>$this->bind_store_id,
  838. 'progress'=>3,
  839. 'num'=>3
  840. ]
  841. ];
  842. }elseif($mini['batch_status'] == 3){//审核中
  843. return [
  844. 'code'=>0,
  845. 'msg'=>"审核中",
  846. 'data'=>[
  847. 'bind_store_id'=>$this->bind_store_id,
  848. 'progress'=>3,
  849. 'num'=>4
  850. ]
  851. ];
  852. }elseif($mini['batch_status'] == 4){
  853. return [
  854. 'code'=>0,
  855. 'msg'=>"小程序签约已拒绝",
  856. 'data'=>[
  857. 'bind_store_id'=>$this->bind_store_id,
  858. 'progress'=>3,
  859. 'num'=>5
  860. ]
  861. ];
  862. }elseif($mini['batch_status'] == 5){//等待商户确认
  863. return [
  864. 'code'=>0,
  865. 'msg'=>"等待商户确认",
  866. 'data'=>[
  867. 'bind_store_id'=>$this->bind_store_id,
  868. 'progress'=>3,
  869. 'num'=>6
  870. ]
  871. ];
  872. }elseif($mini['batch_status'] == 6){//确认成功
  873. $AggregateQrcode = AggregateQrcode::find()->where(['and',['store_id'=>$this->bind_store_id],["<>",'ali_mini_id',""]])->one();
  874. if(!empty($AggregateQrcode->ali_status)){
  875. return [
  876. 'code'=>0,
  877. 'msg'=>"完成",
  878. 'data'=>[
  879. 'bind_store_id'=>$this->bind_store_id,
  880. 'progress'=>5,
  881. 'num'=>1,
  882. 'qrcode_id'=>$AggregateQrcode->id
  883. ]
  884. ];
  885. }else{
  886. return [
  887. 'code'=>0,
  888. 'msg'=>"未绑定聚合码",
  889. 'data'=>[
  890. 'bind_store_id'=>$this->bind_store_id,
  891. 'progress'=>4,
  892. 'num'=>1,
  893. 'qrcode_id'=>$AggregateQrcode->id
  894. ]
  895. ];
  896. }
  897. }elseif($mini['batch_status'] == 8){//审核失败
  898. return [
  899. 'code'=>0,
  900. 'msg'=>"审核失败",
  901. 'data'=>[
  902. 'bind_store_id'=>$this->bind_store_id,
  903. 'progress'=>3,
  904. 'num'=>7,
  905. 'store_face_photo'=>$mini['store_face_photo']
  906. ]
  907. ];
  908. }
  909. }
  910. }
  911. }else{
  912. return [
  913. 'code'=>0,
  914. 'msg'=>"未识别的操作系统",
  915. 'data'=>[
  916. 'num'=>13,
  917. "progress"=>1
  918. ]
  919. ];
  920. }
  921. }
  922. //小程序列表基础数据
  923. public function getUserInfo(){
  924. $saas_user_id = get_saas_user_id();
  925. //佣金
  926. //已到帐
  927. $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');
  928. $is_pay_money['all'] = $query->sum('amount')??'0';
  929. $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';
  930. //未到账
  931. $query = SharingReceiver::find()->where(['user_id' => $saas_user_id, 'is_pay' => 0, 'from' => SharingReceiver::FROM_RECOMMEND,'is_delete'=>0])->andWhere(['like', 'order_no', 'ML']);
  932. $no_pay_money['all'] = $query->sum('amount')??'0';
  933. $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';
  934. //总金额
  935. $query = SharingReceiver::find()->where(['user_id' => $saas_user_id, 'from' => SharingReceiver::FROM_RECOMMEND,'is_delete'=>0])->andWhere(['like', 'order_no', 'ML']);
  936. $all_pay_money['all'] = $query->sum('amount')??'0';
  937. $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';
  938. //分销订单数量
  939. $query = SharingReceiver::find()->where(['user_id' => $saas_user_id, 'from' => SharingReceiver::FROM_RECOMMEND])->andWhere(['like', 'order_no', 'ML']);
  940. $count['all'] = $query->count();
  941. $count['prev'] = $query->andWhere(['and',['<','created_at',strtotime(date('Y-m-d'))],['>','created_at',(strtotime(date('Y-m-d')) - 60*60*24)]])->count();
  942. //头像
  943. $avatar = get_saas_user()->avatar;
  944. //名称
  945. $name = get_saas_user()->name;
  946. //所属店铺
  947. $up_name = SaasUser::findOne(Admin::findOne(Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0])->admin_id)->saas_user_id)->name;
  948. //下级店铺数量
  949. $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  950. if (!$salesman) {
  951. return $this->asJson([
  952. 'code' => 1,
  953. 'msg' => '当前登录账户非业务员'
  954. ]);
  955. }
  956. $store_ids = SalesmanNewStore::find()->where(['salesman_saas_id' => $saas_user_id])
  957. ->andWhere(['>', 'store_id', 0])->select('store_id')->column();
  958. $query = Store::find()->where(['is_delete' => 0]);
  959. $query->andWhere([
  960. 'or',
  961. ['salesman_id' => $salesman->id],//修改店铺业务员时候修改的
  962. ['store_admin' => $saas_user_id],//修改店铺业务员时候修改的
  963. ['in', 'id', $store_ids]//业务员帮助店铺进件时候增加
  964. ]);
  965. $sub_merchant_count['all'] = $query->count();
  966. $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();
  967. //(店铺待审核/待完善/待完成/待处理)
  968. $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  969. $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]);
  970. //待审核
  971. $examineQuery = clone $query;
  972. $examineQuery->andWhere(['sa.status' => 0]);
  973. $examine['all'] = $examineQuery->count();
  974. $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();
  975. //待完善
  976. $repairQuery = clone $query;
  977. $repairQuery->andWhere(['and',['sa.status' => 1],['!=', 'mi.status', 3],['<>','mi.app_status','']]);
  978. $repair['all'] = $repairQuery->count();
  979. $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();
  980. //待完成
  981. $finishQuery = clone $query;
  982. $finishQuery->andWhere(['sa.status' => 1, 'mi.status' => 3,'mi.app_status'=>'12']);
  983. $finish['all'] = $finishQuery->count();
  984. $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();
  985. //待处理
  986. $query->andWhere(['OR',['sa.status' => 0],['and',['sa.status' => 1],['or',['!=', 'mi.status', 3],['<>','mi.app_status','']]]]);
  987. $handle_count['all'] = $query->count();
  988. $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();
  989. //展示微信审核失败信息
  990. $qrcode = AggregateQrcode::find()->where(['salesman_id'=>$salesman->id])->select('id,wx_mini_id,ali_mini_id,salesman_id,store_id')->asArray()->all();
  991. $mini = [];
  992. //拟定通知消息
  993. $notice = [];
  994. foreach($qrcode as $value){
  995. if(!empty($value['wx_mini_id'])){
  996. $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();
  997. $store = Store::find()->where(['id'=>$value['store_id']])->one();
  998. $data['name'] = !empty($store->name)?$store->name:'';
  999. $data['bind_store_id'] = $value['store_id'];
  1000. $data['msg'] = "";
  1001. if(!empty($data)){
  1002. $data['msg'] = !empty($data['status'] == 2)?$data['msg']:$data['fail_reason'];
  1003. }
  1004. $data['type'] = 'weixin';
  1005. if($data['status'] == 2){
  1006. $notice[] = $store->name.'审核失败'.$data['msg'];
  1007. }
  1008. if($data['mini_up'] == 3){
  1009. $notice[] = $store->name.'审核失败'.$data['fail_reason'];
  1010. }
  1011. $mini[] = $data;
  1012. }
  1013. if(!empty($value['ali_mini_id'])){
  1014. $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();
  1015. $store = Store::find()->where(['id'=>$value['store_id']])->one();
  1016. $data['name'] = !empty($store->name)?$store->name:'';
  1017. $data['bind_store_id'] = $value['store_id'];
  1018. $data['type'] = 'ali';
  1019. $data['msg'] = "";
  1020. if(!empty($data)){
  1021. $data['msg'] = !empty($data['is_submit'] == 3)?$data['fail_reason']:'';
  1022. }
  1023. if($data['mini_up'] == 3){
  1024. $notice[] = $store->name.'审核失败'.$data['ali']['fail_reason'];
  1025. }
  1026. $mini[] = $data;
  1027. }
  1028. }
  1029. return [
  1030. 'code' => 0,
  1031. 'msg' => 'success',
  1032. 'data' => [
  1033. 'is_pay_money' => $is_pay_money,//已到账佣金
  1034. 'no_pay_money' => $no_pay_money,//未到账佣金
  1035. 'all_pay_money'=>$all_pay_money,//到账总金额
  1036. 'count' => $count,//分销订单数量
  1037. 'avatar' => $avatar,//头像
  1038. 'name' => $name,//名称
  1039. 'up_name' => $up_name ?: '',//总店
  1040. 'sub_merchant_count'=>$sub_merchant_count, //下级店铺数量
  1041. 'handle_count'=>$handle_count,//待处理数量
  1042. 'mini'=>$mini,//有错误的小程序
  1043. 'examine'=>$examine,//待审核数量
  1044. 'repair'=>$repair,//待完成数量
  1045. 'finish'=>$finish,//已完成数量
  1046. 'notice'=>$notice,
  1047. "id"=>$salesman->id
  1048. ]
  1049. ];
  1050. }
  1051. //获取顶部数量
  1052. public function topNumber($query){
  1053. //待审核
  1054. $examine = clone $query;
  1055. $examine = $examine->andWhere(['sa.status' => 0])->count();
  1056. //待完善
  1057. $repair = clone $query;
  1058. $repair = $repair->andWhere(['and',['sa.status' => 1],['or',['!=', 'mi.status', 0],['<>','mi.app_status','']]])->count();
  1059. //待完成
  1060. $finish = clone $query;
  1061. $finish = $finish->andWhere(['sa.status' => 1, 'mi.status' => 3,'mi.app_status'=>'12'])->count();
  1062. return [
  1063. 'examine'=>$examine,//待审核数量
  1064. 'repair'=>$repair,//待完成数量
  1065. 'finish'=>$finish,//已完成数量
  1066. ];
  1067. }
  1068. public function merchantNewList()
  1069. {
  1070. try {
  1071. // $admin = Admin::findOne(['mobile' => get_saas_user()->mobile, 'type' => 'store', 'is_delete' => 0]);
  1072. $query = Store::find()->where(['s.id' => $this->store_id])->alias('s')->leftJoin(['mi' => MerchantInfo::tableName()], 'mi.bind_store_id = s.id');
  1073. $query->leftJoin(['sc'=>SaasCategory::tableName()],'s.category_id = sc.id')->andWhere(['s.is_delete' => 0, 'mi.is_delete' => 0]);
  1074. $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');
  1075. $pagination = pagination_make($query);
  1076. $list = $pagination['list'];
  1077. foreach ($list as &$value) {
  1078. $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
  1079. $value['cat_name'] = SaasCategory::findOne($value['cat_id'])->name ?: '';
  1080. $value['app_status'] = !empty($value['app_status'])?explode(',',$value['app_status']):[];
  1081. // $StoreSchedule = StoreSchedule::find()->where(['audit_id'=>$value['id']])->one();
  1082. $value['merchant_info'] = [];
  1083. // $license_copy = json_decode($StoreSchedule['merchant_info'],true)['subject_info']['business_license_info']['license_copy'];
  1084. // if(!empty($license_copy)){
  1085. // array_push($value['merchant_info'],$license_copy);
  1086. // }
  1087. //审核状态展示审核资料
  1088. }
  1089. return [
  1090. 'code' => 0,
  1091. 'msg' => 'success',
  1092. 'data' => [
  1093. 'row_count' => $pagination['totalCount'],
  1094. 'page_count' => $pagination['pageNo'],
  1095. 'list' => $list,
  1096. 'examine'=>$res["examine"] ?? 0,//待审核数量
  1097. 'repair'=>$res["repair"] ?? 0,//待完成数量
  1098. 'finish'=>$res["finish"] ?? 0,//已完成数量
  1099. ],
  1100. ];
  1101. } catch (\Exception $e) {
  1102. return [
  1103. 'code' => 0,
  1104. 'msg' => $e->getMessage(),
  1105. 'data' => []
  1106. ];
  1107. }
  1108. }
  1109. //店铺列表
  1110. public function merchantList(){
  1111. ///分类数据
  1112. $category = SaasCategory::find()->where(['is_delete'=>0])->orderBy('created_at DESC,sort DESC')->all();
  1113. ///列表数据
  1114. $page = $this->page;
  1115. $status = $this->status;
  1116. $sort = $this->sort;
  1117. $category_id = $this->category_id;
  1118. $type = $this->type == "weixin" ? 1 : 2;
  1119. $saas_user_id = get_saas_user_id();
  1120. $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  1121. $query = StoreAudit::find()->alias('sa')->leftJoin(['mi' => MerchantInfo::tableName()], 'mi.id = sa.merchant_info_id')
  1122. ->leftJoin(['s' => Store::tableName()], 'mi.bind_store_id = s.id')
  1123. ->where(['sa.salesman_id' => $salesman->id, 'mi.is_delete' => 0]);
  1124. // $query = SaasStoreReferral::find()->alias('ssr')
  1125. // ->leftJoin(['s' => Store::tableName()], 'ssr.store_id = s.id')
  1126. // ->where(['ssr.referral_id' => $saas_user_id]);
  1127. $query->leftJoin(['sc'=>SaasCategory::tableName()],'sa.cat_id = sc.id')->andWhere(['sc.is_delete' => 0]);
  1128. $res = $this->topNumber($query);
  1129. if ($status == 0) {
  1130. // 待审核
  1131. $query->andWhere(['sa.status' => 0]);
  1132. } else {
  1133. // $query->leftJoin(['ssr' => SaasStoreReferral::tableName()]);
  1134. // 审核通过
  1135. $query->andWhere(['sa.status' => 1]);
  1136. }
  1137. if ($status == 1) {
  1138. // 待完善
  1139. // $query->andWhere(['sa.status' => 1]);
  1140. // $query->andWhere([
  1141. // 'OR',['!=', 'mi.status', 3],
  1142. // ['!=','mi.app_status','']
  1143. // ]);
  1144. $query->andWhere([
  1145. 'or',
  1146. [
  1147. 'and',
  1148. ['!=','mi.app_status',''],
  1149. ['!=','mi.app_status','0']
  1150. ],
  1151. 'isnull(mi.app_status)'
  1152. ]);
  1153. }
  1154. if ($status == 2) {
  1155. // 已完成
  1156. $query->andWhere([
  1157. 'or',
  1158. ['=','mi.app_status',''],
  1159. ['=','mi.app_status','0']
  1160. ]);
  1161. }
  1162. //排序
  1163. if($sort == 0){
  1164. $query->orderBy('sa.created_at DESC');
  1165. }elseif($sort == 1 || $sort == 2){
  1166. $query->orderBy('sa.updated_at DESC');
  1167. }
  1168. //分类
  1169. if(!empty($category_id)){
  1170. $query->andWhere(['sc.id'=>$category_id]);
  1171. }
  1172. //小程序类型
  1173. // if(!empty($type) && $status != 0){
  1174. // switch ($status){
  1175. // case 2:
  1176. // $query->andWhere(['NOT LIKE','mi.app_status',$type]);
  1177. // break;
  1178. // default:
  1179. // $query->andWhere(['LIKE','mi.app_status',$type]);
  1180. // break;
  1181. // }
  1182. // }
  1183. //$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');
  1184. //var_dump($query->createCommand()->getRawSql());die;
  1185. $count = $query->count();
  1186. $pagination = new Pagination(['totalCount' => $count, 'page' => $page - 1, 'pageSize' => 20]);
  1187. $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();
  1188. foreach ($list as &$value) {
  1189. $value['created_at'] = date('Y-m-d H:i:s', $value['created_at']);
  1190. $value['cat_name'] = SaasCategory::findOne($value['cat_id'])->name;
  1191. $value['app_status'] = !empty($value['app_status'])?explode(',',$value['app_status']):[];
  1192. // $StoreSchedule = StoreSchedule::find()->where(['audit_id'=>$value['id']])->one();
  1193. $value['merchant_info'] = [];
  1194. // $license_copy = json_decode($StoreSchedule['merchant_info'],true)['subject_info']['business_license_info']['license_copy'];
  1195. // if(!empty($license_copy)){
  1196. // array_push($value['merchant_info'],$license_copy);
  1197. // }
  1198. //审核状态展示审核资料
  1199. }
  1200. $result = [
  1201. 'code' => 0,
  1202. 'msg' => 'success',
  1203. 'data' => [
  1204. 'row_count' => $count,
  1205. 'page_count' => $pagination->pageCount,
  1206. 'list' => $list,
  1207. 'examine'=>$res["examine"] ?? 0,//待审核数量
  1208. 'repair'=>$res["repair"] ?? 0,//待完成数量
  1209. 'finish'=>$res["finish"] ?? 0,//已完成数量
  1210. 'category'=>$category
  1211. ],
  1212. ];
  1213. return $result;
  1214. }
  1215. //审核店铺
  1216. public function audit(){
  1217. $id = $this->id;
  1218. $status = $this->status;
  1219. $business_model = $this->business_model;
  1220. $qrcode_id = $this->qrcode_id;
  1221. $audit = StoreAudit::findOne(['id' => $id, 'status' => 0]);
  1222. if (!$audit) {
  1223. return [
  1224. 'code' => 1,
  1225. 'msg' => '数据不存在'
  1226. ];
  1227. }
  1228. $t = \Yii::$app->db->beginTransaction();
  1229. $saas_user_id = get_saas_user_id();
  1230. if ($status == 1) {
  1231. //TODO 兼容
  1232. // if (empty($qrcode_id) && !\Yii::$app->prod_is_dandianpu()) {
  1233. // return [
  1234. // 'code' => 1,
  1235. // 'msg' => '请填写聚合码ID'
  1236. // ];
  1237. // }
  1238. // if ((int)$business_model === 1) {
  1239. // $AggregateQrcode = AggregateQrcode::findOne($qrcode_id);
  1240. // } else {
  1241. // $AggregateQrcode = AggregateSaasQrcode::findOne($qrcode_id);
  1242. // }
  1243. // if (empty($AggregateQrcode) && !\Yii::$app->prod_is_dandianpu()) {
  1244. // return [
  1245. // 'code' => 1,
  1246. // 'msg' => '对应的聚合码不存在,请重试'
  1247. // ];
  1248. // }
  1249. // 自动创建admin账号
  1250. $admin = new Admin();
  1251. $admin->access_token = \Yii::$app->security->generateRandomString();
  1252. $admin->username = $audit->name;
  1253. // $admin->password = \Yii::$app->security->generatePasswordHash($audit->mobile);
  1254. // 默认密码改为cyyvipcom 与后台添加商城统一
  1255. $admin->password = \Yii::$app->security->generatePasswordHash('123456');
  1256. $admin->mobile = $audit->mobile;
  1257. $admin->name = $audit->name;
  1258. $admin->type = 'store';
  1259. $file_name = \Yii::$app->runtimePath . '/logs/app_wechat.log';
  1260. file_put_contents($file_name, "\r\n" . '[审核开始][' . date('Y-m-d H:i:s') . 1 . ']' , FILE_APPEND);
  1261. if ($admin->save()) {
  1262. $salesman = Salesman::findOne(['saas_user_id' => $saas_user_id, 'is_delete' => 0]);
  1263. $store = new Store();
  1264. $store->admin_id = $admin->id;
  1265. $store->logo = $audit->logo;
  1266. $store->created_at = time();
  1267. $store->business_model = $business_model;
  1268. $store->store_admin = $audit->saas_user_id;
  1269. $store->name = $audit->name;
  1270. $store->open_status = 0;
  1271. $store->salesman_id = $salesman->id;
  1272. $store->end_time = strtotime("+1 year");
  1273. if ($store->save()) {
  1274. file_put_contents($file_name, "\r\n" . '[审核开始][' . date('Y-m-d H:i:s') . 2 . ']' , FILE_APPEND);
  1275. $admin->type_id = $store->id;
  1276. $admin->save();
  1277. // 绑定关系
  1278. // $saas_store_referral = new SaasStoreReferral();
  1279. // $saas_store_referral->store_id = $store->id;
  1280. // $saas_store_referral->referral_id = $saas_user_id;
  1281. // if (!$saas_store_referral->save()) {
  1282. // $t->rollBack();
  1283. // \Yii::error("绑定关系失败");
  1284. // \Yii::error($saas_store_referral->errors);
  1285. // return [
  1286. // 'code' => 1,
  1287. // 'msg' => "绑定关系失败"
  1288. // ];
  1289. // } else {
  1290. //绑定二维码
  1291. if(!empty($AggregateQrcode)){
  1292. $AggregateQrcode->store_id = $store->id;
  1293. $AggregateQrcode->salesman_id = $salesman->id;
  1294. $AggregateQrcode->admin_id = $salesman->admin_id;
  1295. $AggregateQrcode->shop_bind_time = time();
  1296. $res = $AggregateQrcode->save();
  1297. if(!$res){
  1298. \Yii::error("聚合码绑定失败");
  1299. \Yii::error($AggregateQrcode->errors);
  1300. return [
  1301. 'code' => 1,
  1302. 'msg' => "聚合码绑定失败"
  1303. ];
  1304. }
  1305. }
  1306. //
  1307. // $sales_admin = Admin::findOne($salesman->admin_id);
  1308. // $sales_saas_user_id = $sales_admin->saas_user_id;
  1309. // if ($sales_saas_user_id) {
  1310. // // 代理商绑定
  1311. // $saas_store_referral = new SaasStoreReferral();
  1312. // $saas_store_referral->store_id = $store->id;
  1313. // $saas_store_referral->referral_id = $sales_saas_user_id;
  1314. // if (!$saas_store_referral->save()) {
  1315. // $t->rollBack();
  1316. // \Yii::error("代理商失败");
  1317. // \Yii::error($saas_store_referral->errors);
  1318. // return [
  1319. // 'code' => 1,
  1320. // 'msg' => "代理商绑定失败"
  1321. // ];
  1322. // }
  1323. // }
  1324. // }
  1325. // 绑定上级关系
  1326. if ($audit->saas_user_id) {
  1327. // 绑定上级关系
  1328. // if(!SaasStoreReferral::storeBindParent($salesman, $store->id)){
  1329. // $t->rollBack();
  1330. // \Yii::error("绑定上级关系失败");
  1331. // throw new \Exception("绑定上级关系失败");
  1332. // }
  1333. }
  1334. try {
  1335. $merchant = new Merchant();
  1336. } catch (\Exception $e) {
  1337. return [
  1338. 'code' => 1,
  1339. 'msg' => $e->getMessage()
  1340. ];
  1341. }
  1342. file_put_contents($file_name, "\r\n" . '[审核开始][' . date('Y-m-d H:i:s') . 3 . ']' , FILE_APPEND);
  1343. $merchant_info = new MerchantInfo();
  1344. $merchant_info->store_id = get_store_id();
  1345. $merchant_info->saas_user_id = $saas_user_id;
  1346. $merchant_info->business_code = $merchant->getBusinessCode();
  1347. $merchant_info->bind_store_id = $store->id;
  1348. $merchant_info->app_status = "1,2";
  1349. $merchant_info->from = 1;
  1350. if (!$merchant_info->save()) {
  1351. file_put_contents($file_name, "\r\n" . '[审核,保存merchant_info][' . date('Y-m-d H:i:s') . json_encode($merchant_info->errors) . ']' , FILE_APPEND);
  1352. $t->rollBack();
  1353. \Yii::error($merchant_info->errors);
  1354. return [
  1355. 'code' => 1,
  1356. 'msg' => "保存进件信息失败"
  1357. ];
  1358. } else {
  1359. $audit->merchant_info_id = $merchant_info->id;
  1360. if (!$audit->save()) {
  1361. file_put_contents($file_name, "\r\n" . '[审核,保存merchant_info][' . date('Y-m-d H:i:s') . json_encode($audit->errors) . ']' , FILE_APPEND);
  1362. $t->rollBack();
  1363. \Yii::error($audit->errors);
  1364. return [
  1365. 'code' => 1,
  1366. 'msg' => "申请单修改失败"
  1367. ];
  1368. }
  1369. }
  1370. } else {
  1371. $t->rollBack();
  1372. \Yii::error($store->errors);
  1373. return [
  1374. 'code' => 1,
  1375. 'msg' => "店铺新增失败"
  1376. ];
  1377. }
  1378. } else {
  1379. $t->rollBack();
  1380. \Yii::error($admin->errors);
  1381. return [
  1382. 'code' => 1,
  1383. 'msg' => "新增管理员失败"
  1384. ];
  1385. }
  1386. }
  1387. $audit->status = $status;
  1388. if (!$audit->save()) {
  1389. $t->rollBack();
  1390. \Yii::error($audit->errors);
  1391. return [
  1392. 'code' => 1,
  1393. 'msg' => "申请单修改失败。"
  1394. ];
  1395. } else {
  1396. $t->commit();
  1397. //申请通过发送短信
  1398. $res = NoticeSend::AgentExamine($audit->id, 2);
  1399. if (isset($res['code']) && $res['code'] !== 0) {
  1400. debug_log($res, 'sms.log');
  1401. }
  1402. return [
  1403. 'code' => 0,
  1404. 'msg' => '操作成功'
  1405. ];
  1406. }
  1407. }
  1408. //获取收款码
  1409. public function getQrcode ()
  1410. {
  1411. $business_model = (int)$this->business_model;
  1412. if (in_array($business_model, [1, 2, 3, 4])) {
  1413. if ($business_model === 1) {
  1414. $query = AggregateQrcode::find();
  1415. } else {
  1416. $query = AggregateSaasQrcode::find();
  1417. }
  1418. $qrcode = $query->where(['is_use' => 1, 'store_id' => 0])->select('id')->column();
  1419. return [
  1420. 'code' => 0,
  1421. 'msg' => "SUCCESS",
  1422. 'data' => $qrcode
  1423. ];
  1424. }
  1425. return [
  1426. 'code' => 0,
  1427. 'msg' => "SUCCESS",
  1428. 'data' => []
  1429. ];
  1430. }
  1431. //获取进件信息
  1432. public function getInfo(){
  1433. $StoreSchedule = StoreSchedule::find()->where(['store_id'=>$this->bind_store_id])->select("merchant_info")->one();
  1434. $merchant_info = [];
  1435. if(!empty($StoreSchedule)){
  1436. $merchant_info = json_decode($StoreSchedule->$StoreSchedule);
  1437. }
  1438. return $merchant_info;
  1439. }
  1440. /**
  1441. * 生成业务编号
  1442. * @return string
  1443. */
  1444. public function getBusinessCode()
  1445. {
  1446. return date('Ymd') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
  1447. }
  1448. }