liyaozhi
2025-10-29 52b7c373601edbc5010471082eb88dadf70e382d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
 
namespace app\branch\model\branch;
 
use app\common\model\branch\Service as ServiceModel;
use app\branch\model\branch\Branch as BranchModel;
use app\branch\model\branch\User as BranchUserModel;
use app\branch\model\user\User as UserModel;
use app\common\exception\BaseException;
/**
 * 供应商客服模型
 */
class Service extends ServiceModel
{
    /**
     * 保存
     */
    public static function saveService($branch_id, $data)
    {
        $model = static::detail($branch_id);
        if(!$model){
            $model = new static();
            $data['branch_id'] = $branch_id;
            $data['app_id'] = self::$app_id;
        }
        $Branch = BranchModel::detail($branch_id, []);
        //更新供应商绑定用户id
        if (!$Branch['user_id'] && $data['service_type'] == 20) {
            //查询用户id是否存在
            $user = UserModel::detail($data['user_id']);
            if(!$user){
                throw new BaseException(['msg' => '绑定用户信息不存在']);
            }
            //查询用户id是否已绑定
            $branchInfo = (new BranchModel())->where('user_id','=',$data['user_id'])->find();
            if($branchInfo){
                throw new BaseException(['msg' => '该用户已经绑定']);
            }
            $Branch->save(['user_id'=>$data['user_id']]);
            (new BranchUserModel())->where('branch_id','=',$branch_id)->where('is_super','=',1)->update(['user_id'=>$data['user_id']]);
        }
        return $model->save($data);
    }
}