LowPriceGoods.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?php
  2. namespace App\Http\Controllers\Manager\WashConfig;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Manager\WashConfig\LowPriceGoods as Request;
  5. use App\Models\Manager\WashConfig\LowPriceGoods as LowPriceGoodsModel;
  6. use App\Models\Manager\WashConfig\ViolationStore as ViolationStoreModel;
  7. use App\Models\Manager\WashConfig\LowPriceGoodsCompany as LowPriceGoodsCompanyModel;
  8. use App\Models\Manager\WashConfig\ProductCategory as ProductCategoryModel;
  9. /**
  10. * 数据清洗-低价产品配置
  11. * @author 唐远望
  12. * @version 1.0
  13. * @date 2025-12-02
  14. */
  15. class LowPriceGoods extends Controller
  16. {
  17. /**
  18. * 列表
  19. * @author 唐远望
  20. * @version 1.0
  21. * @date 2025-12-02
  22. *
  23. */
  24. public function list(Request $request, LowPriceGoodsModel $LowPriceGoodsModel, ViolationStoreModel $ViolationStoreModel, LowPriceGoodsCompanyModel $LowPriceGoodsCompanyModel, ProductCategoryModel $ProductCategoryModel)
  25. {
  26. $request->scene('list')->validate();
  27. // 查询条件
  28. $map = [];
  29. $limit = request('limit', config('page_num', 10));
  30. $status = request('status', '');
  31. $start_time = request('start_time', '');
  32. $end_time = request('end_time', '');
  33. $product_name = request('product_name', '');
  34. $platform = request('platform', '');
  35. $store_scope = request('store_scope', '');
  36. $company_scope = request('company_scope', '');
  37. $category_id = request('category_id', '');
  38. // 时间条件
  39. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  40. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  41. // 其他条件
  42. if (is_numeric($status)) $map[] = ['status', '=', $status];
  43. if ($product_name) $map[] = ['product_name', 'like', "%$product_name%"];
  44. if ($platform) $map[] = ['platform', 'like', "%$platform%"];
  45. if ($store_scope) $map[] = ['store_scope', '=',$store_scope];
  46. if ($company_scope) $map[] = ['company_scope', '=',$company_scope];
  47. if ($category_id) $map[] = ['category_id', '=', $category_id];
  48. // 查询数据
  49. $result = $LowPriceGoodsModel->query()
  50. ->where($map)
  51. ->orderByDesc('id')
  52. ->paginate($limit)->toarray();
  53. // 分配数据
  54. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  55. if (isset($result['data']) && count($result['data']) > 0) {
  56. foreach ($result['data'] as $key => $value) {
  57. $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : '';
  58. $category_name = $value['category_id'] > 0 ? $ProductCategoryModel->where('id', $value['category_id'])->value('name'):'';
  59. $result['data'][$key]['category_name'] = $category_name;
  60. //查询店铺名称
  61. if ($value['store_scope'] == '1') {
  62. $result['data'][$key]['store_name'] = ['全部店铺'];
  63. } else {
  64. $result['data'][$key]['store_name'] = '';
  65. }
  66. //查询公司名称
  67. if ($value['company_scope'] == '1') {
  68. $result['data'][$key]['company_name'] = ['全部公司'];
  69. } else {
  70. $company_data = $LowPriceGoodsCompanyModel->where('lowprice_product_logid', $value['id'])
  71. ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_lowprice_product_company.company_id')
  72. ->select(['washconfig_violation_store.id', 'washconfig_violation_store.company_name', 'washconfig_lowprice_product_company.company_id'])->get()->toArray();
  73. $result['data'][$key]['company_name'] = !empty($company_data) ? array_column($company_data, 'company_name') : '';
  74. }
  75. }
  76. }
  77. // 加载模板
  78. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  79. }
  80. /**
  81. * 详情
  82. * @author 唐远望
  83. * @version 1.0
  84. * @date 2025-12-02
  85. */
  86. public function detail(Request $request, LowPriceGoodsModel $LowPriceGoodsModel,LowPriceGoodsCompanyModel $LowPriceGoodsCompanyModel, ProductCategoryModel $ProductCategoryModel)
  87. {
  88. $request->scene('detail')->validate();
  89. // 接收参数
  90. $id = request('id', 0);
  91. $map = ['id' => $id];
  92. $data = $LowPriceGoodsModel->where($map)->first();
  93. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  94. //查询店铺名称
  95. if (trim($data['store_scope']) == '') {
  96. $data['store_name'] = ['全部店铺'];
  97. } else {
  98. $data['store_name'] = '';
  99. }
  100. //查询公司名称
  101. if ($data->company_scope == '1') {
  102. $data->company_name = ['全部公司'];
  103. $data->company_ids ='';
  104. } else {
  105. $company_data = $LowPriceGoodsCompanyModel->where('lowprice_product_logid', $data->id)
  106. ->join('washconfig_violation_store', 'washconfig_violation_store.id', '=', 'washconfig_lowprice_product_company.company_id')
  107. ->select(['washconfig_violation_store.id', 'washconfig_violation_store.company_name', 'washconfig_lowprice_product_company.company_id'])->get()->toArray();
  108. $data->company_name = !empty($company_data) ? array_column($company_data, 'company_name') : '';
  109. $data->company_ids = !empty($company_data) ? array_column($company_data, 'company_id') : '';
  110. }
  111. $data->platform = isset($data->platform) ? explode(',',$data->platform) : '';
  112. $data->category_name = $data->category_id > 0 ? $ProductCategoryModel->where('id', $data->category_id)->value('name'):'';
  113. // 加载模板
  114. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  115. }
  116. /**
  117. * 添加
  118. * @author 唐远望
  119. * @version 1.0
  120. * @date 2025-12-02
  121. *
  122. */
  123. public function add(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  124. {
  125. $request->scene('add')->validate();
  126. // 接收数据
  127. $all_data = request()->all();
  128. $store_scope = request('store_scope', '');
  129. $all_data['store_scope'] = $store_scope;
  130. $company_scope = request('company_scope', '');
  131. $all_data['company_scope'] = $company_scope;
  132. $category_id = request('category_id', '');
  133. $all_data['category_id'] = $category_id;
  134. //查询是否存在
  135. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
  136. $data = $LowPriceGoodsModel->where($map)->first();
  137. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  138. // 写入数据表
  139. $result = $LowPriceGoodsModel->addLowProduct($all_data);
  140. // 如果操作失败
  141. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  142. // 告知结果
  143. return json_send(['code' => 'success', 'msg' => '新增成功']);
  144. }
  145. /**
  146. * 修改
  147. * @author 唐远望
  148. * @version 1.0
  149. * @date 2025-12-02
  150. *
  151. */
  152. public function edit(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  153. {
  154. $request->scene('edit')->validate();
  155. // 接收参数
  156. $id = request('id', 0);
  157. // 接收数据
  158. $all_data = request()->all();
  159. $store_scope = request('store_scope', '');
  160. $all_data['store_scope'] = $store_scope;
  161. $company_scope = request('company_scope', '');
  162. $all_data['company_scope'] = $company_scope;
  163. $category_id = request('category_id', '');
  164. $all_data['category_id'] = $category_id;
  165. //查询是否存在
  166. $map = ['product_name' => $all_data['product_name'], 'product_specs' => $all_data['product_specs'], 'platform' => $all_data['platform']];
  167. $data = $LowPriceGoodsModel->where($map)->where('id', '!=', $id)->first();
  168. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  169. // 更新数据表
  170. $where = ['id' => $id];
  171. $result = $LowPriceGoodsModel->updateLowProduct($where, $all_data);
  172. // 如果操作失败
  173. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  174. // 告知结果
  175. return json_send(['code' => 'success', 'msg' => '修改成功']);
  176. }
  177. /**
  178. * 修改状态
  179. * @author 唐远望
  180. * @version 1.0
  181. * @date 2025-12-02
  182. *
  183. */
  184. public function set_status(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  185. {
  186. // 验证参数
  187. $request->scene('set_status')->validate();
  188. // 接收数据
  189. $id = request('id', 0);
  190. $status = request('status', 0);
  191. // 查询用户
  192. $where = ['id' => $id];
  193. // 执行修改
  194. $result = $LowPriceGoodsModel->changeStatus($where, $status);
  195. // 提示新增失败
  196. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  197. // 告知结果
  198. return json_send(['code' => 'success', 'msg' => '设置成功']);
  199. }
  200. /**
  201. * 删除
  202. * @author 唐远望
  203. * @version 1.0
  204. * @date 2025-12-02
  205. *
  206. */
  207. public function delete(Request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  208. {
  209. // 验证参数
  210. $request->scene('delete')->validate();
  211. // 接收数据
  212. $id = request('id', 0);
  213. // 查询用户
  214. $where = ['id' => $id];
  215. // 执行删除
  216. $result = $LowPriceGoodsModel->deleteLowProduct($where);
  217. // 提示删除失败
  218. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  219. // 告知结果
  220. return json_send(['code' => 'success', 'msg' => '删除成功']);
  221. }
  222. }