BasicPanel.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <?php
  2. namespace App\Http\Controllers\manager\Statistics;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\Manager\Statistics\BasicPanel as request;
  5. use App\Models\Manager\Process\LowPriceGoods as LowPriceGoodsModel;
  6. use App\Models\Manager\Process\ViolationProduct as ViolationProductModel;
  7. use App\Models\Manager\Process\ViolationStore as ViolationStoreModel;
  8. use App\Models\Manager\Collect\Product as ProductModel;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Support\Carbon;
  11. /**
  12. * 报表统计-基础概览面板
  13. * @author 唐远望
  14. * @version 1.0
  15. * @date 2026-02-10
  16. *
  17. */
  18. class BasicPanel extends Controller
  19. {
  20. /*
  21. * 挂网数据统计
  22. * @author 唐远望
  23. * @version 1.0
  24. * @date 2026-02-10
  25. *
  26. */
  27. public function get_online_goods_count(request $request, LowPriceGoodsModel $lowPriceGoodsModel, ViolationProductModel $violationProductModel, ViolationStoreModel $violationStoreModel, ProductModel $productModel)
  28. {
  29. $request->scene('get_online_goods_count')->validate();
  30. $admin_company_id = request('admin_company_id', '0');
  31. $company_id = request('access_token.company_id', '0');
  32. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  33. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  34. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  35. $start_time_string = request('start_time', '');
  36. $end_time_string = request('end_time', '');
  37. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  38. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  39. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  40. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  41. // 时间条件
  42. $map = [];
  43. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  44. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  45. // 统计挂网商品数量=低价挂网商品数量(去重)+ 禁止挂网商品数量(去重)
  46. $lowPriceGoodsModel = $lowPriceGoodsModel->query();
  47. $violationProductModel = $violationProductModel->query();
  48. if ($is_admin != 1 && $company_id != 0) {
  49. $lowPriceGoodsModel = $lowPriceGoodsModel->where('company_id', $company_id);
  50. $violationProductModel = $violationProductModel->where('company_id', $company_id);
  51. } else {
  52. $lowPriceGoodsModel = $lowPriceGoodsModel->where('company_id', $admin_company_id);
  53. $violationProductModel = $violationProductModel->where('company_id', $admin_company_id);
  54. }
  55. // 低价挂网商品数量查询
  56. $lowPriceGoodsCount = $lowPriceGoodsModel->where($map)
  57. ->where('status', 0)
  58. ->groupBy('product_name')
  59. ->count(DB::raw('DISTINCT product_name'));
  60. // 禁止挂网商品数量查询
  61. $violationProductCount = $violationProductModel->where($map)
  62. ->where('status', 0)
  63. ->groupBy('product_name')
  64. ->count(DB::raw('DISTINCT product_name'));
  65. // 违规店铺数量查询
  66. $violationStoreCount = $violationStoreModel->where($map)
  67. ->where('status', 0)
  68. ->groupBy('company_name')
  69. ->count(DB::raw('DISTINCT company_name'));
  70. //获取终端类型B端、C端、OTO,配置品规数量
  71. $collect_b_product_count = $productModel->whereIn('platform', ['5', '6', '7', '8', '9', '10'])->where('status', 0)->sum('product_specs_number');
  72. $collect_c_product_count = $productModel->whereIn('platform', ['1', '2', '3', '4'])->where('status', 0)->sum('product_specs_number');
  73. $collect_oto_product_count = $productModel->whereIn('platform', [])->where('status', 0)->sum('product_specs_number');
  74. // 所有终端品规数量
  75. $collect_totle_product_count = $collect_b_product_count + $collect_c_product_count + $collect_oto_product_count;
  76. $result_data = [
  77. 'low_price_goods_count' => $lowPriceGoodsCount, // 低价挂网商品数量
  78. 'violation_product_count' => $violationProductCount, // 禁止挂网商品数量
  79. 'violation_store_count' => $violationStoreCount, // 违规店铺数量
  80. 'totle_product_count' => $lowPriceGoodsCount + $violationProductCount, // 总商品数量
  81. 'collect_b_product_count' => $collect_b_product_count, // B端品规数量
  82. 'collect_c_product_count' => $collect_c_product_count, // C端品规数量
  83. 'collect_oto_product_count' => $collect_oto_product_count, // OTO品规数量
  84. 'collect_totle_product_count' => $collect_totle_product_count, // 所有终端品规数量
  85. ];
  86. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result_data]);
  87. }
  88. /**
  89. * 禁止挂网商品数统计
  90. * @author 唐远望
  91. * @version 1.0
  92. * @date 2026-02-10
  93. *
  94. */
  95. public function get_violation_product_count(request $request, ViolationProductModel $violationProductModel)
  96. {
  97. $request->scene('get_violation_product_count')->validate();
  98. $admin_company_id = request('admin_company_id', '0');
  99. //终端类型B端、C端、OTO
  100. $terminal_type = request('terminal_type', '');
  101. $company_id = request('access_token.company_id', '0');
  102. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  103. $limit = request('limit', config('page_num', 10));
  104. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  105. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  106. $start_time_string = request('start_time', '');
  107. $end_time_string = request('end_time', '');
  108. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  109. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  110. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  111. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  112. // 时间条件
  113. $map = [];
  114. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  115. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  116. // 权限判断
  117. if ($is_admin != 1 && $company_id != 0) {
  118. $map[] = ['company_id', '=', $company_id];
  119. } else {
  120. $map[] = ['company_id', '=', $admin_company_id];
  121. }
  122. $violationProductModel = $violationProductModel->query();
  123. if ($terminal_type) {
  124. $platform = [];
  125. switch ($terminal_type) {
  126. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  127. $platform = ['5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  128. break;
  129. case '2': //C端:美团、拼多多、天猫、京东
  130. $platform = ['1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  131. break;
  132. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  133. $platform = [];
  134. break;
  135. default:
  136. # code...
  137. break;
  138. }
  139. $violationProductModel = $violationProductModel->whereIn('platform_id', $platform);
  140. }
  141. $result = $violationProductModel->where($map)->where('status', 0)
  142. ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
  143. ->groupby('product_name')->paginate($limit);
  144. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  145. }
  146. /**
  147. * 禁止挂网省份统计
  148. * @author 唐远望
  149. * @version 1.0
  150. * @date 2026-02-10
  151. *
  152. */
  153. public function get_violation_province_count(request $request, ViolationProductModel $violationProductModel)
  154. {
  155. $request->scene('get_violation_province_count')->validate();
  156. $admin_company_id = request('admin_company_id', '0');
  157. $company_id = request('access_token.company_id', '0');
  158. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  159. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  160. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  161. $start_time_string = request('start_time', '');
  162. $end_time_string = request('end_time', '');
  163. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  164. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  165. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  166. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  167. // 时间条件
  168. $map = [];
  169. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  170. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  171. // 权限判断
  172. if ($is_admin != 1 && $company_id != 0) {
  173. $map[] = ['company_id', '=', $company_id];
  174. } else {
  175. $map[] = ['company_id', '=', $admin_company_id];
  176. }
  177. // 禁止挂网省份统计
  178. // 获取省份字段并按数量分组统计
  179. try {
  180. // 假设 ViolationProductModel 中有 province 字段,表示省份信息
  181. // 查询指定时间范围内的数据,并按 province 分组统计数量
  182. $result = ViolationProductModel::where($map)->where('status', 0)
  183. ->select(['province_name', DB::raw('count(province_name) as count')])
  184. ->groupby('province_name')
  185. ->orderby('count', 'desc')
  186. ->get();
  187. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  188. } catch (\Exception $e) {
  189. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  190. }
  191. }
  192. /**
  193. * 禁止挂网城市统计
  194. * @author 唐远望
  195. * @version 1.0
  196. * @date 2026-02-10
  197. *
  198. */
  199. public function get_violation_city_count(request $request, ViolationProductModel $violationProductModel)
  200. {
  201. $request->scene('get_violation_city_count')->validate();
  202. $admin_company_id = request('admin_company_id', '0');
  203. $company_id = request('access_token.company_id', '0');
  204. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  205. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  206. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  207. $start_time_string = request('start_time', '');
  208. $end_time_string = request('end_time', '');
  209. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  210. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  211. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  212. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  213. // 时间条件
  214. $map = [];
  215. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  216. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  217. // 权限判断
  218. if ($is_admin != 1 && $company_id != 0) {
  219. $map[] = ['company_id', '=', $company_id];
  220. } else {
  221. $map[] = ['company_id', '=', $admin_company_id];
  222. }
  223. // 禁止挂网城市统计
  224. // 获取城市字段并按数量分组统计
  225. try {
  226. // 假设 ViolationProductModel 中有 city 字段,表示城市信息
  227. // 查询指定时间范围内的数据,并按 city 分组统计数量
  228. $result = ViolationProductModel::where($map)->where('status', 0)
  229. ->select(['city_name', DB::raw('count(city_name) as count')])
  230. ->groupby('city_name')
  231. ->orderby('count', 'desc')
  232. ->get();
  233. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  234. } catch (\Exception $e) {
  235. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  236. }
  237. }
  238. /**
  239. * 禁止挂网公司数统计
  240. * @author 唐远望
  241. * @version 1.0
  242. * @date 2026-02-10
  243. *
  244. */
  245. public function get_violation_company_count(request $request, ViolationProductModel $violationProductModel)
  246. {
  247. $request->scene('get_violation_company_count')->validate();
  248. $admin_company_id = request('admin_company_id', '0');
  249. $company_id = request('access_token.company_id', '0');
  250. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  251. $limit = request('limit', config('page_num', 10));
  252. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  253. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  254. $start_time_string = request('start_time', '');
  255. $end_time_string = request('end_time', '');
  256. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  257. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  258. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  259. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  260. // 时间条件
  261. $map = [];
  262. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  263. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  264. // 权限判断
  265. if ($is_admin != 1 && $company_id != 0) {
  266. $map[] = ['company_id', '=', $company_id];
  267. } else {
  268. $map[] = ['company_id', '=', $admin_company_id];
  269. }
  270. $result = $violationProductModel->where($map)->where('status', 0)
  271. ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
  272. ->paginate($limit);
  273. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  274. }
  275. /*
  276. * 低价违规商品数统计
  277. * @author 唐远望
  278. * @version 1.0
  279. * @date 2026-02-10
  280. *
  281. */
  282. public function get_low_price_product_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  283. {
  284. $request->scene('get_low_price_product_count')->validate();
  285. $admin_company_id = request('admin_company_id', '0');
  286. $company_id = request('access_token.company_id', '0');
  287. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  288. $limit = request('limit', config('page_num', 10));
  289. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  290. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  291. $start_time_string = request('start_time', '');
  292. $end_time_string = request('end_time', '');
  293. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  294. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  295. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  296. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  297. // 时间条件
  298. $map = [];
  299. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  300. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  301. // 权限判断
  302. if ($is_admin != 1 && $company_id != 0) {
  303. $map[] = ['company_id', '=', $company_id];
  304. } else {
  305. $map[] = ['company_id', '=', $admin_company_id];
  306. }
  307. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  308. ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
  309. ->groupby('product_name')->paginate($limit);
  310. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  311. }
  312. /*
  313. * 低价违规公司数统计
  314. * @author 唐远望
  315. * @version 1.0
  316. * @date 2026-02-10
  317. *
  318. */
  319. public function get_low_price_company_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  320. {
  321. $request->scene('get_low_price_company_count')->validate();
  322. $admin_company_id = request('admin_company_id', '0');
  323. $company_id = request('access_token.company_id', '0');
  324. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  325. $limit = request('limit', config('page_num', 10));
  326. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  327. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  328. $start_time_string = request('start_time', '');
  329. $end_time_string = request('end_time', '');
  330. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  331. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  332. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  333. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  334. // 时间条件
  335. $map = [];
  336. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  337. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  338. // 权限判断
  339. if ($is_admin != 1 && $company_id != 0) {
  340. $map[] = ['company_id', '=', $company_id];
  341. } else {
  342. $map[] = ['company_id', '=', $admin_company_id];
  343. }
  344. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  345. ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
  346. ->paginate($limit);
  347. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  348. }
  349. /**
  350. * 低价挂网省份统计
  351. * @author 唐远望
  352. * @version 1.0
  353. * @date 2026-02-10
  354. *
  355. */
  356. public function get_low_price_province_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  357. {
  358. $request->scene('get_low_price_province_count')->validate();
  359. $admin_company_id = request('admin_company_id', '0');
  360. $company_id = request('access_token.company_id', '0');
  361. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  362. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  363. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  364. $start_time_string = request('start_time', '');
  365. $end_time_string = request('end_time', '');
  366. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  367. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  368. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  369. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  370. // 时间条件
  371. $map = [];
  372. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  373. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  374. // 权限判断
  375. if ($is_admin != 1 && $company_id != 0) {
  376. $map[] = ['company_id', '=', $company_id];
  377. } else {
  378. $map[] = ['company_id', '=', $admin_company_id];
  379. }
  380. // 禁止挂网省份统计
  381. // 获取省份字段并按数量分组统计
  382. try {
  383. // 假设 LowPriceGoodsModel 中有 province 字段,表示省份信息
  384. // 查询指定时间范围内的数据,并按 province 分组统计数量
  385. $result = LowPriceGoodsModel::where($map)->where('status', 0)
  386. ->select(['province_name', DB::raw('count(province_name) as count')])
  387. ->groupby('province_name')
  388. ->orderby('count', 'desc')
  389. ->get();
  390. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  391. } catch (\Exception $e) {
  392. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  393. }
  394. }
  395. /**
  396. * 低价挂网城市统计
  397. * @author 唐远望
  398. * @version 1.0
  399. * @date 2026-02-10
  400. *
  401. */
  402. public function get_low_price_city_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  403. {
  404. $request->scene('get_low_price_city_count')->validate();
  405. $admin_company_id = request('admin_company_id', '0');
  406. $company_id = request('access_token.company_id', '0');
  407. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  408. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  409. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  410. $start_time_string = request('start_time', '');
  411. $end_time_string = request('end_time', '');
  412. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  413. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  414. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  415. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  416. // 时间条件
  417. $map = [];
  418. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  419. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  420. // 权限判断
  421. if ($is_admin != 1 && $company_id != 0) {
  422. $map[] = ['company_id', '=', $company_id];
  423. } else {
  424. $map[] = ['company_id', '=', $admin_company_id];
  425. }
  426. // 禁止挂网城市统计
  427. // 获取城市字段并按数量分组统计
  428. try {
  429. // 假设 LowPriceGoodsModel 中有 city 字段,表示城市信息
  430. // 查询指定时间范围内的数据,并按 city 分组统计数量
  431. $result = LowPriceGoodsModel::where($map)->where('status', 0)
  432. ->select(['city_name', DB::raw('count(city_name) as count')])
  433. ->groupby('city_name')
  434. ->orderby('count', 'desc')
  435. ->get();
  436. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  437. } catch (\Exception $e) {
  438. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  439. }
  440. }
  441. }