<?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);
|
}
|
}
|