ViolationCompany.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. namespace App\Http\Controllers\Manager\WashConfig;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Manager\WashConfig\ViolationCompany as Request;
  5. use App\Models\Manager\WashConfig\ViolationCompany as ViolationCompanyModel;
  6. use App\Models\Manager\WashConfig\LowPriceGoodsCompany as LowPriceGoodsCompanyModel;
  7. use App\Models\Manager\WashConfig\ViolationProductCompany as ViolationProductCompanyModel;
  8. use App\Models\Manager\Personnel\Employee as EmployeeModel;
  9. use App\Models\Manager\WashConfig\CompanyCategory as CompanyCategoryModel;
  10. use App\Models\Manager\Citys as CitysModel;
  11. /**
  12. * 数据清洗-违规店铺(公司)配置
  13. * @author 唐远望
  14. * @version 1.0
  15. * @date 2025-12-03
  16. */
  17. class ViolationCompany extends Controller
  18. {
  19. /**
  20. * 列表
  21. * @author 唐远望
  22. * @version 1.0
  23. * @date 2025-12-03
  24. *
  25. */
  26. public function list(Request $request, ViolationCompanyModel $ViolationCompanyModel, EmployeeModel $EmployeeModel, CompanyCategoryModel $CompanyCategoryModel, CitysModel $CitysModel)
  27. {
  28. $request->scene('list')->validate();
  29. $admin_company_id = request('admin_company_id', '0');
  30. $company_id = request('access_token.company_id', '0');
  31. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  32. // 查询条件
  33. $map = [];
  34. $limit = request('limit', config('page_num', 10));
  35. $status = request('status', '');
  36. $start_time = request('start_time', '');
  37. $end_time = request('end_time', '');
  38. $company_name = request('company_name', '');
  39. $social_credit_code = request('social_credit_code', '');
  40. $company_type = request('company_type', '');
  41. $category_id = request('category_id', '');
  42. // 时间条件
  43. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  44. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  45. // 其他条件
  46. if (is_numeric($status)) $map[] = ['status', '=', $status];
  47. if ($social_credit_code) $map[] = ['social_credit_code', 'like', "%$social_credit_code%"];
  48. if ($company_name) $map[] = ['company_name', 'like', "%$company_name%"];
  49. if ($company_type) $map[] = ['company_type', '=', $company_type];
  50. if ($category_id) $map[] = ['category_id', '=', $category_id];
  51. // 查询数据
  52. if ($is_admin != 1 && $company_id != 0){
  53. $map[] = ['company_id', '=', $company_id];
  54. }else{
  55. $map[] = ['company_id', '=', $admin_company_id];
  56. }
  57. $result = $ViolationCompanyModel->query()
  58. ->where($map)
  59. ->orderByDesc('id')
  60. ->paginate($limit)->toarray();
  61. // 分配数据
  62. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  63. if (isset($result['data']) && count($result['data']) > 0) {
  64. foreach ($result['data'] as $key => $value) {
  65. $employee_ids = $value['employee_ids'] != '' ? explode(',', $value['employee_ids']) : '';
  66. $result['data'][$key]['platform'] = isset($value['platform']) ? explode(',', $value['platform']) : '';
  67. $result['data'][$key]['employee_ids'] = $employee_ids;
  68. $result['data'][$key]['employee_name'] = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
  69. $result['data'][$key]['category_name'] = $value['category_id'] ? $CompanyCategoryModel->where('id', $value['category_id'])->value('name') : '';
  70. $province_name = $CitysModel->get_city_name($value['province_id']);
  71. $result['data'][$key]['province_name'] = $province_name ?? '';
  72. $city_name = $CitysModel->get_city_name($value['city_id']);
  73. $result['data'][$key]['city_name'] = $city_name ?? '';
  74. }
  75. }
  76. // 加载模板
  77. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  78. }
  79. /**
  80. * 全部
  81. * @author 唐远望
  82. * @version 1.0
  83. * @date 2025-12-08
  84. *
  85. */
  86. public function all(Request $request, ViolationCompanyModel $ViolationCompanyModel)
  87. {
  88. $request->scene('all')->validate();
  89. $admin_company_id = request('admin_company_id', '0');
  90. $company_id = request('access_token.company_id', '0');
  91. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  92. // 查询条件
  93. $map = [];
  94. $status = request('status', '0');
  95. $start_time = request('start_time', '');
  96. $end_time = request('end_time', '');
  97. $company_name = request('company_name', '');
  98. $social_credit_code = request('social_credit_code', '');
  99. $category_id = request('category_id', '');
  100. // 时间条件
  101. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time)];
  102. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time)];
  103. // 其他条件
  104. if (is_numeric($status)) $map[] = ['status', '=', $status];
  105. if ($social_credit_code) $map[] = ['social_credit_code', 'like', "%$social_credit_code%"];
  106. if ($company_name) $map[] = ['company_name', 'like', "%$company_name%"];
  107. if ($category_id) $map[] = ['category_id', '=', $category_id];
  108. // 查询数据
  109. if ($is_admin != 1 && $company_id != 0){
  110. $map[] = ['company_id', '=', $company_id];
  111. }else{
  112. $map[] = ['company_id', '=', $admin_company_id];
  113. }
  114. $result = $ViolationCompanyModel->query()
  115. ->where($map)
  116. ->orderByDesc('id')
  117. ->get();
  118. // 分配数据
  119. if (!$result) return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => []]);
  120. // 加载模板
  121. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  122. }
  123. /**
  124. * 详情
  125. * @author 唐远望
  126. * @version 1.0
  127. * @date 2025-12-03
  128. */
  129. public function detail(Request $request, ViolationCompanyModel $ViolationCompanyModel, EmployeeModel $EmployeeModel, CompanyCategoryModel $CompanyCategoryModel, CitysModel $CitysModel)
  130. {
  131. $request->scene('detail')->validate();
  132. $admin_company_id = request('admin_company_id', '0');
  133. $company_id = request('access_token.company_id', '0');
  134. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  135. // 接收参数
  136. $id = request('id', 0);
  137. $map = ['id' => $id];
  138. if ($is_admin != 1 && $company_id != 0) {
  139. $map['company_id'] = $company_id;
  140. } else {
  141. $map['company_id'] = $admin_company_id;
  142. }
  143. $data = $ViolationCompanyModel->where($map)->first();
  144. if (!$data) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  145. $employee_ids = $data->employee_ids != '' ? explode(',', $data->employee_ids) : '';
  146. $data->employee_ids = $employee_ids;
  147. $data->employee_name = $employee_ids ? $EmployeeModel->whereIn('id', $employee_ids)->pluck('name')->toArray() : '';
  148. $data->category_name = $data->category_id ? $CompanyCategoryModel->where('id', $data->category_id)->value('name') : '';
  149. $province_name = $CitysModel->get_city_name($data->province_id);
  150. $data->province_name = $province_name ?? '';
  151. $city_name = $CitysModel->get_city_name($data->city_id);
  152. $data->city_name = $city_name ?? '';
  153. $data->platform = isset($data->platform) ? explode(',', $data->platform) : '';
  154. // 加载模板
  155. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
  156. }
  157. /**
  158. * 添加
  159. * @author 唐远望
  160. * @version 1.0
  161. * @date 2025-12-03
  162. *
  163. */
  164. public function add(Request $request, ViolationCompanyModel $ViolationCompanyModel)
  165. {
  166. $request->scene('add')->validate();
  167. $admin_company_id = request('admin_company_id', '0');
  168. $company_id = request('access_token.company_id', '0');
  169. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  170. // 接收数据
  171. $all_data = request()->all();
  172. $store_scope = request('store_scope', '');
  173. $all_data['store_scope'] = $store_scope; //店铺范围
  174. $employee_ids = request('employee_ids', '');
  175. $all_data['employee_ids'] = $employee_ids;
  176. $category_id = request('category_id', '0');
  177. $all_data['category_id'] = $category_id;
  178. $specify_responsible_person = request('specify_responsible_person', '0');
  179. $all_data['specify_responsible_person'] = $specify_responsible_person;
  180. $area_info = request('area_info', '');
  181. $all_data['area_info'] = $area_info;
  182. $platform = request('platform', '0');
  183. $all_data['platform'] = $platform;
  184. //查询是否存在
  185. $map = ['social_credit_code' => $all_data['social_credit_code']];
  186. if ($is_admin != 1 && $company_id != 0) {
  187. $map['company_id'] = $company_id;
  188. $all_data['company_id'] = $company_id;
  189. } else {
  190. $map['company_id'] = $admin_company_id;
  191. $all_data['company_id'] = $admin_company_id;
  192. }
  193. $data = $ViolationCompanyModel->where($map)->first();
  194. if ($data) return json_send(['code' => 'error', 'msg' => '营业执照记录已存在']);
  195. // 写入数据表
  196. $result = $ViolationCompanyModel->addViolationCompany($all_data);
  197. // 如果操作失败
  198. if (!$result) return json_send(['code' => 'error', 'msg' => '新增失败']);
  199. // 记录行为
  200. $admin_id = request('access_token.uid', 0); //用户ID
  201. $table_name = $ViolationCompanyModel->getTable();
  202. $notes_type = 1; //操作类型,1添加,2修改,3=删除
  203. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], $all_data, '新增了公司' . $all_data['company_name'] . '信息');
  204. // 告知结果
  205. return json_send(['code' => 'success', 'msg' => '新增成功']);
  206. }
  207. /**
  208. * 修改
  209. * @author 唐远望
  210. * @version 1.0
  211. * @date 2025-12-03
  212. *
  213. */
  214. public function edit(Request $request, ViolationCompanyModel $ViolationCompanyModel)
  215. {
  216. $request->scene('edit')->validate();
  217. $admin_company_id = request('admin_company_id', '0');
  218. $company_id = request('access_token.company_id', '0');
  219. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  220. // 接收参数
  221. $id = request('id', 0);
  222. // 接收数据
  223. $all_data = request()->all();
  224. $store_scope = request('store_scope', '');
  225. $all_data['store_scope'] = $store_scope;
  226. $employee_ids = request('employee_ids', '');
  227. $all_data['employee_ids'] = $employee_ids;
  228. $category_id = request('category_id', '0');
  229. $all_data['category_id'] = $category_id;
  230. $specify_responsible_person = request('specify_responsible_person', '0');
  231. $all_data['specify_responsible_person'] = $specify_responsible_person;
  232. $area_info = request('area_info', '');
  233. $all_data['area_info'] = $area_info;
  234. $platform = request('platform', '0');
  235. $all_data['platform'] = $platform;
  236. //查询是否存在
  237. $map = ['social_credit_code' => $all_data['social_credit_code']];
  238. if ($is_admin != 1 && $company_id != 0) {
  239. $map['company_id'] = $company_id;
  240. } else {
  241. $map['company_id'] = $admin_company_id;
  242. }
  243. $data = $ViolationCompanyModel->where($map)->where('id', '!=', $id)->first();
  244. if ($data) return json_send(['code' => 'error', 'msg' => '记录已存在']);
  245. // 更新数据表
  246. $where = ['id' => $id];
  247. if ($is_admin != 1 && $company_id != 0) {
  248. $where['company_id'] = $company_id;
  249. } else {
  250. $where['company_id'] = $admin_company_id;
  251. }
  252. $ViolationCompany = $ViolationCompanyModel->where($where)->first();
  253. if (!$ViolationCompany) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  254. $oldData = $ViolationCompany->toarray();
  255. $all_data['company_id'] = $map['company_id'];
  256. $result = $ViolationCompanyModel->updateViolationCompany($ViolationCompany, $all_data);
  257. // 如果操作失败
  258. if (!$result) return json_send(['code' => 'error', 'msg' => '修改失败']);
  259. // 记录行为
  260. $admin_id = request('access_token.uid', 0); //用户ID
  261. $table_name = $ViolationCompanyModel->getTable();
  262. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  263. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $oldData, $all_data, '修改了公司' . $oldData['company_name'] . '信息');
  264. // 告知结果
  265. return json_send(['code' => 'success', 'msg' => '修改成功']);
  266. }
  267. /**
  268. * 修改状态
  269. * @author 唐远望
  270. * @version 1.0
  271. * @date 2025-12-03
  272. *
  273. */
  274. public function set_status(Request $request, ViolationCompanyModel $ViolationCompanyModel)
  275. {
  276. // 验证参数
  277. $request->scene('set_status')->validate();
  278. $admin_company_id = request('admin_company_id', '0');
  279. $company_id = request('access_token.company_id', '0');
  280. $is_admin = request('access_token.is_admin', '0');//是否管理员操作 0=是1=否
  281. // 接收数据
  282. $id = request('id', 0);
  283. $status = request('status', 0);
  284. // 查询用户
  285. $where = ['id' => $id];
  286. if ($is_admin != 1 && $company_id != 0) {
  287. $where['company_id'] = $company_id;
  288. } else {
  289. $where['company_id'] = $admin_company_id;
  290. }
  291. $ViolationCompany = $ViolationCompanyModel->where($where)->first();
  292. if (!$ViolationCompany) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  293. // 执行修改
  294. $result = $ViolationCompanyModel->changeStatus($ViolationCompany, $status);
  295. // 提示新增失败
  296. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  297. // 记录行为
  298. $admin_id = request('access_token.uid', 0); //用户ID
  299. $table_name = $ViolationCompanyModel->getTable();
  300. $notes_type = 2; //操作类型,1添加,2修改,3=删除
  301. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, [], ['status' => $status], '修改了公司' . $ViolationCompany->company_name . '状态');
  302. // 告知结果
  303. return json_send(['code' => 'success', 'msg' => '设置成功']);
  304. }
  305. /**
  306. * 删除
  307. * @author 唐远望
  308. * @version 1.0
  309. * @date 2025-12-03
  310. *
  311. */
  312. public function delete(Request $request, ViolationCompanyModel $ViolationCompanyModel, LowPriceGoodsCompanyModel $LowPriceGoodsCompanyModel, ViolationProductCompanyModel $ViolationProductCompanyModel)
  313. {
  314. // 验证参数
  315. $request->scene('delete')->validate();
  316. $admin_company_id = request('admin_company_id', '0');
  317. $company_id = request('access_token.company_id', '0');
  318. $is_admin = request('access_token.is_admin', '0');
  319. // 接收数据
  320. $id = request('id', 0);
  321. $company_where = ['company_id' => $id];
  322. if ($is_admin != 1 && $company_id != 0) {
  323. $company_where['company_id'] = $company_id;
  324. } else {
  325. $company_where['company_id'] = $admin_company_id;
  326. }
  327. //查询是否已经被使用
  328. $use_low_price_goods_company_log = $LowPriceGoodsCompanyModel->where($company_where)->first();
  329. if ($use_low_price_goods_company_log) {
  330. return json_send(['code' => 'error', 'msg' => '该记录已被使用在低价商品配置中,不能删除']);
  331. }
  332. $use_violation_product_company_log = $ViolationProductCompanyModel->where($company_where)->first();
  333. if ($use_violation_product_company_log) {
  334. return json_send(['code' => 'error', 'msg' => '该记录已被使用在违规商品配置中,不能删除']);
  335. }
  336. // 查询用户
  337. $where = ['id' => $id];
  338. if ($is_admin != 1 && $company_id != 0) {
  339. $where['company_id'] = $company_id;
  340. } else {
  341. $where['company_id'] = $admin_company_id;
  342. }
  343. // 执行删除
  344. $ViolationCompany = $ViolationCompanyModel->where($where)->first();
  345. if (!$ViolationCompany) return json_send(['code' => 'error', 'msg' => '记录不存在']);
  346. $result = $ViolationCompany->delete();
  347. // 提示删除失败
  348. if (!$result) return json_send(['code' => 'error', 'msg' => '删除失败']);
  349. // 记录行为
  350. $admin_id = request('access_token.uid', 0); //用户ID
  351. $is_admin = request('access_token.is_admin'); //是否管理员操作 0=是1=否
  352. $table_name = $ViolationCompanyModel->getTable();
  353. $notes_type = 3; //操作类型,1添加,2修改,3=删除
  354. $this->addAdminHistory('清洗配置-公司管理',$company_id, $admin_id, $is_admin, $table_name, $notes_type, $ViolationCompany->toarray(), [], '删除了公司' . $ViolationCompany->company_name . '信息');
  355. // 告知结果
  356. return json_send(['code' => 'success', 'msg' => '删除成功']);
  357. }
  358. }