|
|
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
|
|
use App\Http\Requests\Manager\WashConfig\ControlGoods as Request;
|
|
|
use App\Models\Manager\WashConfig\ControlGoods as ControlGoodsModel;
|
|
|
use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
|
|
|
+use App\Models\Manager\WashConfig\ControlGoodsCompany as ControlGoodsCompanyModel;
|
|
|
|
|
|
/**
|
|
|
* 数据清洗-强管控商品配置
|
|
|
@@ -22,7 +23,7 @@ class ControlGoods extends Controller
|
|
|
* @date 2025-12-03
|
|
|
*
|
|
|
*/
|
|
|
- public function list(Request $request, ControlGoodsModel $ControlGoodsModel,ViolationStoreModel $ViolationStoreModel)
|
|
|
+ public function list(Request $request, ControlGoodsModel $ControlGoodsModel, ViolationStoreModel $ViolationStoreModel, ControlGoodsCompanyModel $ControlGoodsCompanyModel)
|
|
|
{
|
|
|
$request->scene('list')->validate();
|
|
|
// 查询条件
|
|
|
@@ -42,8 +43,8 @@ class ControlGoods extends Controller
|
|
|
if ($status) $map[] = ['status', '=', $status];
|
|
|
if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
|
|
|
if ($platform) $map[] = ['platform', 'like', "%$platform%"];
|
|
|
- if ($store_scope) $map[] = ['store_scope', '=',$store_scope];
|
|
|
- if ($company_scope) $map[] = ['company_scope', '=',$company_scope];
|
|
|
+ if ($store_scope) $map[] = ['store_scope', '=', $store_scope];
|
|
|
+ if ($company_scope) $map[] = ['company_scope', '=', $company_scope];
|
|
|
// 查询数据
|
|
|
$result = $ControlGoodsModel->query()
|
|
|
->where($map)
|
|
|
@@ -51,16 +52,23 @@ class ControlGoods extends Controller
|
|
|
->paginate($limit)->toarray();
|
|
|
// 分配数据
|
|
|
if (!$result) return json_send(['code' => 'error', 'msg' => '暂无数据']);
|
|
|
- if(isset($result['data']) && count($result['data']) > 0){
|
|
|
+ if (isset($result['data']) && count($result['data']) > 0) {
|
|
|
foreach ($result['data'] as $key => $value) {
|
|
|
- $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',',$value['platform']) : '';
|
|
|
+ $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : '';
|
|
|
//查询店铺名称
|
|
|
- if(trim($value['store_scope']) == ''){
|
|
|
- $result['data'][$key]['store_name'] =['全部店铺'];
|
|
|
- }else{
|
|
|
- $store_scope = explode(',',$value['store_scope']);
|
|
|
- $store_name = $ViolationStoreModel->whereIn('id',$store_scope)->pluck('store_name');
|
|
|
- $result['data'][$key]['store_name'] = $store_name;
|
|
|
+ if (trim($value['store_scope']) == '') {
|
|
|
+ $result['data'][$key]['store_name'] = ['全部店铺'];
|
|
|
+ } else {
|
|
|
+ $result['data'][$key]['store_name'] = '';
|
|
|
+ }
|
|
|
+ //查询公司名称
|
|
|
+ if ($value['company_scope'] == '1') {
|
|
|
+ $result['data'][$key]['company_name'] = ['全部公司'];
|
|
|
+ } else {
|
|
|
+ $company_data = $ControlGoodsCompanyModel->where('control_product_logid', $value['id'])
|
|
|
+ ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_control_product_company.company_id')
|
|
|
+ ->select(['washconfig_violation_store.id', 'washconfig_violation_store.company_name', 'washconfig_control_product_company.company_id'])->get()->toArray();
|
|
|
+ $result['data'][$key]['company_name'] = !empty($company_data) ? array_column($company_data, 'company_name') : '';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -74,7 +82,7 @@ class ControlGoods extends Controller
|
|
|
* @version 1.0
|
|
|
* @date 2025-12-03
|
|
|
*/
|
|
|
- public function detail(Request $request, ControlGoodsModel $ControlGoodsModel,ViolationStoreModel $ViolationStoreModel)
|
|
|
+ public function detail(Request $request, ControlGoodsModel $ControlGoodsModel, ViolationStoreModel $ViolationStoreModel, ControlGoodsCompanyModel $ControlGoodsCompanyModel)
|
|
|
{
|
|
|
$request->scene('detail')->validate();
|
|
|
// 接收参数
|
|
|
@@ -83,14 +91,21 @@ class ControlGoods extends Controller
|
|
|
$data = $ControlGoodsModel->where($map)->first();
|
|
|
if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
|
|
|
//查询店铺名称
|
|
|
- if(trim($data['store_scope']) == ''){
|
|
|
+ if (trim($data['store_scope']) == '') {
|
|
|
$data['store_name'] = ['全部店铺'];
|
|
|
- }else{
|
|
|
- $store_scope = explode(',',$data['store_scope']);
|
|
|
- $store_name = $ViolationStoreModel->whereIn('id',$store_scope)->pluck('store_name');
|
|
|
- $data['store_name'] = $store_name;
|
|
|
+ } else {
|
|
|
+ $data['store_name'] = '';
|
|
|
+ }
|
|
|
+ //查询公司名称
|
|
|
+ if ($data->company_scope == '1') {
|
|
|
+ $data->company_name = ['全部公司'];
|
|
|
+ } else {
|
|
|
+ $company_data = $ControlGoodsCompanyModel->where('control_product_logid', $data->id)
|
|
|
+ ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_control_product_company.company_id')
|
|
|
+ ->select(['washconfig_violation_store.id', 'washconfig_violation_store.company_name', 'washconfig_control_product_company.company_id'])->get()->toArray();
|
|
|
+ $data->company_name = !empty($company_data) ? array_column($company_data, 'company_name') : '';
|
|
|
}
|
|
|
- $data->platform = isset($data->platform) ? explode(',',$data->platform) : '';
|
|
|
+ $data->platform = isset($data->platform) ? explode(',', $data->platform) : '';
|
|
|
// 加载模板
|
|
|
return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
|
|
|
}
|
|
|
@@ -110,7 +125,7 @@ class ControlGoods extends Controller
|
|
|
$store_scope = request('store_scope', '');
|
|
|
$all_data['store_scope'] = $store_scope;
|
|
|
//查询是否存在
|
|
|
- $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'],'platform'=> $all_data['platform']];
|
|
|
+ $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
|
|
|
$data = $ControlGoodsModel->where($map)->first();
|
|
|
if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
|
|
|
// 写入数据表
|
|
|
@@ -135,10 +150,10 @@ class ControlGoods extends Controller
|
|
|
$id = request('id', 0);
|
|
|
// 接收数据
|
|
|
$all_data = request()->all();
|
|
|
- $store_scope = request('store_scope','');
|
|
|
+ $store_scope = request('store_scope', '');
|
|
|
$all_data['store_scope'] = $store_scope;
|
|
|
- //查询是否存在
|
|
|
- $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'],'platform'=> $all_data['platform']];
|
|
|
+ //查询是否存在
|
|
|
+ $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
|
|
|
$data = $ControlGoodsModel->where($map)->where('id', '!=', $id)->first();
|
|
|
if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
|
|
|
// 更新数据表
|