LowPriceGoods.php 9.0 KB

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