|
@@ -183,10 +183,10 @@ class Account
|
|
|
|
|
|
//查找供应商名称
|
|
|
$supplierName = Db::name('supplier')
|
|
|
- ->where(['code' => $param['supplierNo']])
|
|
|
- ->value('name', '');
|
|
|
+ ->whereIn('code', $param['supplierNo'])
|
|
|
+ ->column('name', 'code');
|
|
|
|
|
|
- if ($supplierName == '') return json_show(1004, '该供应商名称不存在');
|
|
|
+ if (empty($supplierName)) return json_show(1004, '供应商不存在');
|
|
|
|
|
|
Db::connect('mysql_sys')->startTrans();
|
|
|
|
|
@@ -201,7 +201,6 @@ class Account
|
|
|
'mobile' => $param['mobile'],
|
|
|
])->findOrEmpty();
|
|
|
|
|
|
- $is_insert = true;
|
|
|
if ($res->isEmpty()) {
|
|
|
//新增账号
|
|
|
$password = get_encryption_password(Config::get('app.default_password'));
|
|
@@ -219,32 +218,32 @@ class Account
|
|
|
|
|
|
$res->status = $db::$status_normal;
|
|
|
|
|
|
- } else {
|
|
|
+ }
|
|
|
|
|
|
- $rs = SupplierRelationUserModel::field('id')
|
|
|
- ->where([
|
|
|
- 'is_del' => $db::$is_del_normal,
|
|
|
- 'uid' => $res->uid,
|
|
|
- 'supplierNo' => $param['supplierNo'],
|
|
|
- ])->findOrEmpty()
|
|
|
- ->isEmpty();
|
|
|
+ $relation = SupplierRelationUserModel::where([
|
|
|
+ 'is_del' => $db::$is_del_normal,
|
|
|
+ 'uid' => $res->uid
|
|
|
+ ])->whereIn('supplierNo', $param['supplierNo'])
|
|
|
+ ->column('id', 'supplierNo');
|
|
|
|
|
|
- if ($rs) throw new Exception('不能重复添加');//该关联关系已存在,无需新增
|
|
|
- else $is_insert = false;
|
|
|
+ $insert_data = [];
|
|
|
+ foreach ($param['supplierNo'] as $supplierNo) {
|
|
|
|
|
|
+ if (isset($relation[$supplierNo])) continue;
|
|
|
+ else {
|
|
|
+ $insert_data[] = [
|
|
|
+ 'uid' => $res->uid,
|
|
|
+ 'supplierNo' => $supplierNo,
|
|
|
+ 'supplierName' => $supplierName[$supplierNo] ?? '',
|
|
|
+ 'status' => $res->status,
|
|
|
+ 'is_del' => $db::$is_del_normal,
|
|
|
+ 'createrid' => $user['data']['user_id'] ?? 0,
|
|
|
+ 'creater' => $user['data']['nickname'] ?? '',
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if ($is_insert) {
|
|
|
- SupplierRelationUserModel::create([
|
|
|
- 'uid' => $res->uid,
|
|
|
- 'supplierNo' => $param['supplierNo'],
|
|
|
- 'supplierName' => $supplierName,
|
|
|
- 'status' => $res->status,
|
|
|
- 'is_del' => $db::$is_del_normal,
|
|
|
- 'createrid' => $user['data']['user_id'] ?? 0,
|
|
|
- 'creater' => $user['data']['nickname'] ?? '',
|
|
|
- ])->save();
|
|
|
- }
|
|
|
+ if ($insert_data) Db::connect('mysql_sys')->name('supplier_relation_user')->insertAll($insert_data);
|
|
|
|
|
|
Db::connect('mysql_sys')->commit();
|
|
|
return json_show(0, '操作成功');
|