ViolationCompany.php 18 KB

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