|
@@ -52,22 +52,26 @@ class CompanyGoodLogic extends BaseLogic
|
|
|
->isEmpty();
|
|
|
if ($rs) return json_show(CommonModel::$error_param, '该分组不存在');
|
|
|
|
|
|
- $rs = GoodModel::field('id')
|
|
|
- ->where(['id' => $data['good_id'], 'is_del' => CommonModel::$del_normal])
|
|
|
- ->findOrEmpty()
|
|
|
- ->isEmpty();
|
|
|
- if ($rs) return json_show(CommonModel::$error_param, '该商品不存在');
|
|
|
+ $data['good_id'] = GoodModel::where('is_del', CommonModel::$del_normal)
|
|
|
+ ->whereIn('id', $data['good_id'])
|
|
|
+ ->column('id');
|
|
|
+ if (empty($data['good_id'])) return json_show(CommonModel::$error_param, '该商品不存在');
|
|
|
|
|
|
- $rs = CompanyGoodModel::field('id')
|
|
|
- ->where(['is_del' => CommonModel::$del_normal, 'group_id' => $data['group_id'], 'good_id' => $data['good_id']])
|
|
|
+ $rs = CompanyGoodModel::field('a.id,a.good_id,b.good_name,b.good_code')
|
|
|
+ ->alias('a')
|
|
|
+ ->leftJoin('good b', 'b.id=a.good_id AND b.is_del=' . CommonModel::$del_normal)
|
|
|
+ ->where(['a.is_del' => CommonModel::$del_normal, 'a.group_id' => $data['group_id']])
|
|
|
+ ->whereIn('a.good_id', $data['good_id'])
|
|
|
->findOrEmpty()
|
|
|
- ->isEmpty();
|
|
|
- if (!$rs) return json_show(CommonModel::$error_param, '该公司商品已存在');
|
|
|
+ ->toArray();
|
|
|
+ if (empty($rs)) return json_show(CommonModel::$error_layer, "【{$rs['good_code']}】【{$rs['good_name']}】该商品重复添加");
|
|
|
|
|
|
$res = CompanyGoodModel::create((array_merge($data, [
|
|
|
'code' => makeNo('CG'),
|
|
|
'is_del' => CommonModel::$del_normal,
|
|
|
'status' => CommonModel::$status_normal,
|
|
|
+ 'is_top' => CommonModel::$top_no,
|
|
|
+ 'weight' => 0,
|
|
|
'creater' => self::$uname,
|
|
|
'createrid' => self::$uid,
|
|
|
'addtime' => date('Y-m-d H:i:s'),
|