xieruidong 2 年之前
父節點
當前提交
8a1b4da4f7
共有 2 個文件被更改,包括 38 次插入0 次删除
  1. 11 0
      app/admin/controller/Merchant.php
  2. 27 0
      app/data/model/SystemUser.php

+ 11 - 0
app/admin/controller/Merchant.php

@@ -3,7 +3,11 @@
 namespace app\admin\controller;
 
 use app\data\model\DataMerchants;
+use Carbon\Carbon;
 use think\admin\Controller;
+use think\admin\model\SystemUser;
+use think\facade\Db;
+
 /**
  * 商家管理
  * Class Xw
@@ -45,12 +49,19 @@ class Merchant extends Controller
             'why.requireIf:audit,3'=>'原因必须',
         ]);
         $row=DataMerchants::with(['user'])->find($id    );
+        $row->startTrans();
         if($row['audit']!=1){
             $this->error('该信息已审核');
         }
         $row['audit']=$data['audit'];
         $row['why']=$data['why'];
+        $row['audit_at']=Carbon::now()->toDateTimeString();
         $row->save();
+        if($row['audit']==2){
+            #创建商家账号
+            \app\data\model\SystemUser::createMerchant($row);
+        }
+        $row->commit();
         $this->success('审核成功');
     }
 }

+ 27 - 0
app/data/model/SystemUser.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\data\model;
+
+use think\admin\Model;
+
+/**
+ * 商城商品主模型
+ * Class ShopGoods
+ * @package app\data\model
+ */
+class SystemUser extends Model
+{
+    public static function createMerchant(DataMerchants $merchants){
+        $has=self::where('username',$merchants->contact_phone)->find();
+        throw_if($has,'该商家已存在无法创建');
+        $user=new self;
+        $user->username=$merchants->contact_phone;
+        $user->contact_phone=$merchants->contact_phone;
+        $user->nickname=$merchants['name'];
+        $user->headimg=$merchants['head_img'];
+        $user->authorize=",156,";
+        $user->save();
+        $merchants['admin_id']=$user->id;
+        $merchants->save();
+    }
+}