cqp hace 3 meses
padre
commit
4d319ab6ec

+ 6 - 1
app/Http/Controllers/Api/TestController.php

@@ -23,6 +23,8 @@ use App\Service\OrderNoService;
 use App\Service\SalesOrderService;
 use App\Service\TPlusDatabaseServerService;
 use App\Service\WDTService;
+use App\Service\Weixin\WeixinService;
+use App\Service\Weixin\WxTemplateMessageService;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Hash;
@@ -40,7 +42,10 @@ class TestController extends BaseController
 
     }
 
-    public function aa(){echo 'ok';die;
+    public function aa(){(new WeixinService())->getTokenSTABLE();dd(1);
+        list($a,$b) = (new WxTemplateMessageService())->sendTemplateMessage( 'audit_result',
+        ['title' => '出差申请', 'status' => '审核通过', 'time' => '2025-10-31'],
+        ['url' => 'https://example.com/wechat/audit/1']);dd($a,$b);echo 'ok';die;
         $service = new TPlusDatabaseServerService(true);
         if(! empty($service->error)) return [false, $service->error];
         list($s, $msg) = $service->getSnList(["sn_type"=>1,"code"=>"1000004805"],[]);

+ 6 - 0
app/Model/WxEmployeeOfficial.php

@@ -17,4 +17,10 @@ class WxEmployeeOfficial extends Model
     protected $dateFormat = 'U';
     const SPECIAL_ADMIN = 1;
 
+    const login_type_one = 1;
+    const login_type_two = 2;
+    public static $login_type_title = [
+        self::login_type_one => '供应商绑定',
+        self::login_type_two => '企业员工绑定',
+    ];
 }

+ 7 - 1
app/Service/CustomerSupplyService.php

@@ -82,7 +82,7 @@ class CustomerSupplyService extends Service
 
             $account = str_pad($model->id, 10, '0', STR_PAD_LEFT);
             CustomerSupply::where('id', $model->id)
-                ->update(['account'=> $account]);
+                ->update(['account'=> $account, 'password' => $this->createPassword()]);
 
             $this->saveDetail($model->id, time(), $data);
 
@@ -95,6 +95,10 @@ class CustomerSupplyService extends Service
         return [true, ''];
     }
 
+    private function createPassword(){
+        return substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'), 0, 8);
+    }
+
     private function saveDetail($id, $time, $data){
         if(! empty($data['organization'])){
             $unit = [];
@@ -228,6 +232,8 @@ class CustomerSupplyService extends Service
         if(empty($data['title'])) return [false, '名称不能为空'];
         if(empty($data['type'])) return [false, '人员类型不能为空'];
         if(! isset(CustomerSupply::$type_name[$data['type']])) return [false, '人员类型错误'];
+        if(empty($data['mobile'])) return [false, '手机号码不能为空'];
+        if(! $this->isValidPhone($data['mobile'])) return [false, '手机号码格式错误'];
         if(! empty($data['status']) && ! isset(CustomerSupply::$status_name[$data['status']])) return [false, '合作状态错误'];
         list($status, $msg) = $this->checkArrayRepeat($data['organization'],'organization_id','组织');
         if(! $status) return [false, $msg];

+ 4 - 4
app/Service/Service.php

@@ -2,10 +2,6 @@
 
 namespace App\Service;
 
-
-use App\Jobs\OperationLog;
-use App\Model\Depart;
-use App\Model\Employee;
 use Illuminate\Support\Facades\Redis;
 use Illuminate\Support\Facades\Storage;
 
@@ -944,4 +940,8 @@ class Service
 
         return [true, ''];
     }
+
+    function isValidPhone($phone) {
+        return preg_match('/^1(3\d|4[5-9]|5[0-35-9]|6[5-7]|7[0-8]|8\d|9[0-35-9])\d{8}$/', $phone);
+    }
 }

+ 2 - 2
app/Service/Weixin/WeixinService.php

@@ -74,7 +74,7 @@ class WeixinService extends Service
         $uri = isset($data['uri']) ? $data['uri'] : '';
         $url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
         $param = isset($data['param']) ? $data['param'] : '';
-        $redirect_uri = urlencode('https://t9api.qingyaokeji.com/wxapi/getUnionid?uri='.$uri.'&param='.$param);
+        $redirect_uri = urlencode('https://xlkjapi.qingyaokeji.com/wxapi/getUnionid?uri='.$uri.'&param='.$param);
         $url = sprintf($url,$this->appid,$redirect_uri);
         header("Location:".$url);exit;
         echo 'ok';die;
@@ -91,7 +91,7 @@ class WeixinService extends Service
             $uri = $data['uri'];
             $openid = $openid['openid'];
             $param = isset($data['param']) ? $data['param'] : '';
-            $url = 'https://t9.qingyaokeji.com/#/wxGet?uri='.$uri.'&openid='.$openid.'&param='.$param;
+            $url = 'https://xlkj.qingyaokeji.com/#/wxGet?uri='.$uri.'&openid='.$openid.'&param='.$param;
             header('Location:'.$url);exit();
         }
     }

+ 65 - 65
app/Service/Weixin/WxEmployeeService.php

@@ -2,98 +2,98 @@
 
 namespace App\Service\Weixin;
 
+use App\Model\CustomerSupply;
 use App\Model\Employee;
 use App\Model\WxEmployeeOfficial;
 use App\Service\Service;
-use App\Model\WxEmployee;
-use Illuminate\Support\Facades\Hash;
 
 class WxEmployeeService extends Service
 {
     public function setUser($data){
-        if(empty($data['openid'])) return [false, 'openId不能为空!'];
+        if(empty($data['openid'])) return [false, 'openid不能为空'];
+        if(empty($data['login_type']) || ! isset(WxEmployeeOfficial::$login_type_title[$data['login_type']])) return [false, '绑定类型不存在或错误'];
         $openid = $data['openid'];
-        $user = WxEmployeeOfficial::where('openid',$openid)->first();
+        $appid = config("wx_msg.f_appid");
+        $user = WxEmployeeOfficial::where('openid',$openid)
+            ->where('type', $data['login_type'])
+            ->where('appid', $appid)
+            ->first();
+
+        $state = 0;
         if(empty($user)) {
             $user = new WxEmployeeOfficial();
             $user->openid = $openid;
-            $user->appid = WeixinService::APPID;
+            $user->type = $data['login_type'];
+            $user->appid = $appid;
             $user->save();
-            $state = 0;
         }else{
-            $state = 1;
-            if(empty($user->employee_id)) $state = 0;
+            if(! empty($user->employee_id)) $state = 1;
         }
 
-        return [true,['openid'=>$openid, 'state'=>$state ]];
+        return [true, ['openid'=>$openid, 'state'=>$state]];
     }
 
-    public function login($data,$openid){
-        if(empty($data['account'])) return [false, '账号不能为空'];
-        if(empty($data['password'])) return [false, '密码不能为空'];
-        if(empty($openid) || $openid == null) return [false, 'ciphertext不能为空'];
-
-        $account = $data['account'];
-        $password = $data['password'];
-        list($status,$data) = $this->loginRule([
-            'account' => $account,
-            'password' => $password,
-        ]);
-        if(! $status) return [false, $data];
+    public function login($data, $openid){
+        list($status, $a_data) = $this->loginRule($data, $openid);
+        if(! $status) return [false, $a_data];
+        list($user, $customer) = $a_data;
 
-        $user_id = $data['id'];
-        $user = WxEmployeeOfficial::where('openid',$openid)->first();
+        try{
+            $user->employee_id = $customer['id'];
+            $user->save();
+        }catch (\Exception $exception){
+            return [false, $exception->getMessage()];
+        }
 
-        if(empty($user)) {
-            $bool = WxEmployeeOfficial::where('employee_id',$user_id)->exists();
-            if($bool) return [false,'该账号已经与其他微信用户绑定!'];
+        return [true, ''];
+    }
 
+    public function loginRule($data, $openid){
+        if(empty($data['account'])) return [false, '账号不能为空'];
+        if(empty($data['password'])) return [false, '密码不能为空'];
+        if(empty($openid) || $openid == null) return [false, 'ciphertext不能为空'];
+        if(empty($data['login_type']) || ! isset(WxEmployeeOfficial::$login_type_title[$data['login_type']])) return [false, '绑定类型不存在或错误'];
+
+        $appid = config("wx_msg.f_appid");
+        $user = WxEmployeeOfficial::where('openid',$openid)
+            ->where('type', $data['login_type'])
+            ->where('appid',$appid)
+            ->first();
+        if(! empty($user)) {
+            if(! empty($user->employee_id)) return [false, '微信用户已绑定系统账号'];
+        }else{
             $user = new WxEmployeeOfficial();
             $user->openid = $openid;
-            $user->appid = WeixinService::APPID;
-            $user->employee_id = $user_id;
+            $user->type = $data['login_type'];
+            $user->appid = $appid;
             $user->save();
-        }else{
-            if(empty($user->employee_id)){
-                $bool = WxEmployeeOfficial::where('employee_id',$user_id)->exists();
-                if($bool) return [false,'该账号已经与其他微信用户绑定!'];
-                $user->employee_id = $user_id;
-                $user->save();
-            }
-            if(! empty($user->employee_id) && $user->employee_id != $user_id) return [false,'该账号已经与其他微信用户绑定!'];
         }
 
-        return [true, $data];
-    }
-
-    public function loginRule($data){
-        if($this->isEmpty($data,'account')) return [false,'账号不能为空!'];
-        if($this->isEmpty($data,'password')) return [false,'密码不存在!'];
-
-        $account = $data['account'];
-        $res = Employee::where('del_time',0)
-            ->where(function ($query)use($account) {
-                $query->where('account', $account)
-                    ->orWhere('mobile', $account);
-            })
-            ->get()->toArray();
-
-        if(empty($res)) return [false,'账号不存在或已被删除!'];
-        if(count($res) > 1) return [false,'手机号绑定多个账户!'];
-
-        $res = reset($res);
-        if($res['state'] == Employee::NOT_USE) return [false,'账号停用!'];
-        if(empty($res['password'])){
-            if(empty($res['mobile'])) return [false, '用户手机号码信息不能为空'];
-            $lastFour = substr($res['mobile'], -4);
-            if($lastFour != $data['password']) return [false,'密码错误!'];
-
-            Employee::where('id', $res['id'])
-                ->update(['password' => Hash::make($data['password'])]);
+        if($data['login_type'] == WxEmployeeOfficial::login_type_one){
+            //供应商
+            $customer = CustomerSupply::where('del_time',0)
+                ->where('account', $data['account'])
+                ->where('password', $data['password'])
+                ->first();
+            if(empty($customer)) return [false, '账号或者密码错误,绑定失败'];
+            $customer = $customer->toArray();
         }else{
-            if(! Hash::check($data['password'], $res['password'])) return [false,'密码错误!'];
+            //企业内部员工
+            $customer = Employee::where('del_time',0)
+                ->where('account', $data['account'])
+                ->first();
+            if(empty($customer)) return [false,'账号不存在,绑定失败'];
+            $customer = $customer->toArray();
+            if($customer['state'] == Employee::NOT_USE) return [false,'账号停用,绑定失败'];
+            $lastFour = substr($customer['mobile'], -4);
+            if($lastFour != $data['password']) return [false,'密码错误,绑定失败'];
         }
+        $bool = WxEmployeeOfficial::where('employee_id',$customer['id'])
+            ->where('type', $data['login_type'])
+            ->where('appid',$appid)
+            ->exists();
+        if($bool) return [false, '系统账号已被其他微信用户绑定,绑定失败'];
 
-        return [true, ['id'=>$res['id'], 'name'=>$res['emp_name'], 'account' => $res['account']]];
+        return [true, [$user, $customer]];
     }
 }

+ 5 - 1
config/header/66.php

@@ -16,7 +16,11 @@ return [
     ],
     [
         'key' =>'account',
-        'value' => '分配账号',
+        'value' => '微信公众号分配账号',
+    ],
+    [
+        'key' =>'password',
+        'value' => '微信公众号分配密码',
     ],
     [
         'key' =>'type_title',