BasicPanel.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  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. $product_name = request('product_name', ''); //商品名称
  34. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  35. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  36. $start_time_string = request('start_time', '');
  37. $end_time_string = request('end_time', '');
  38. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  39. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  40. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  41. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  42. // 时间条件
  43. $map = [];
  44. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  45. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  46. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  47. // 统计挂网商品数量=低价挂网商品数量(去重)+ 禁止挂网商品数量(去重)
  48. $lowPriceGoodsModel = $lowPriceGoodsModel->query();
  49. $violationProductModel = $violationProductModel->query();
  50. if ($is_admin != 1 && $company_id != 0) {
  51. $lowPriceGoodsModel = $lowPriceGoodsModel->where('company_id', $company_id);
  52. $violationProductModel = $violationProductModel->where('company_id', $company_id);
  53. $violationStoreModel = $violationStoreModel->where('company_id', $company_id);
  54. } else {
  55. $lowPriceGoodsModel = $lowPriceGoodsModel->where('company_id', $admin_company_id);
  56. $violationProductModel = $violationProductModel->where('company_id', $admin_company_id);
  57. $violationStoreModel = $violationStoreModel->where('company_id', $admin_company_id);
  58. }
  59. // 低价挂网商品数量查询
  60. $lowPriceGoodsCount = $lowPriceGoodsModel->where($map)
  61. ->where('status', 0)
  62. ->groupBy('product_name')
  63. ->select('product_name')
  64. ->get()->count();
  65. // 禁止挂网商品数量查询
  66. $violationProductCount = $violationProductModel->where($map)
  67. ->where('status', 0)
  68. ->groupBy('product_name')
  69. ->select('product_name')
  70. ->get()->count();
  71. $store_map = [];
  72. if ($start_time) $store_map[] = ['insert_time', '>=', $start_time];
  73. if ($end_time) $store_map[] = ['insert_time', '<=', $end_time];
  74. // 违规店铺数量查询
  75. $violationStoreCount = $violationStoreModel->where($store_map)
  76. ->where('status', 0)
  77. ->groupBy('company_name')
  78. ->select('company_name')
  79. ->get()->count();
  80. //获取终端类型B端、C端、OTO,配置品规数量
  81. $collect_b_product_count = $productModel->whereIn('platform', ['5', '6', '7', '8', '9', '10'])->where('status', 0)->sum('product_specs_number');
  82. $collect_c_product_count = $productModel->whereIn('platform', ['1', '2', '3', '4'])->where('status', 0)->sum('product_specs_number');
  83. $collect_oto_product_count = $productModel->whereIn('platform', [])->where('status', 0)->sum('product_specs_number');
  84. // 所有终端品规数量
  85. $collect_totle_product_count = $collect_b_product_count + $collect_c_product_count + $collect_oto_product_count;
  86. $result_data = [
  87. 'low_price_goods_count' => $lowPriceGoodsCount, // 低价挂网商品数量
  88. 'violation_product_count' => $violationProductCount, // 禁止挂网商品数量
  89. 'violation_store_count' => $violationStoreCount, // 违规店铺数量
  90. 'totle_product_count' => $lowPriceGoodsCount + $violationProductCount, // 总商品数量
  91. 'collect_b_product_count' => $collect_b_product_count, // B端品规数量
  92. 'collect_c_product_count' => $collect_c_product_count, // C端品规数量
  93. 'collect_oto_product_count' => $collect_oto_product_count, // OTO品规数量
  94. 'collect_totle_product_count' => $collect_totle_product_count, // 所有终端品规数量
  95. ];
  96. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result_data]);
  97. }
  98. /**
  99. * 禁止挂网商品数统计
  100. * @author 唐远望
  101. * @version 1.0
  102. * @date 2026-02-10
  103. *
  104. */
  105. public function get_violation_product_count(request $request, ViolationProductModel $violationProductModel)
  106. {
  107. $request->scene('get_violation_product_count')->validate();
  108. $admin_company_id = request('admin_company_id', '0');
  109. $company_id = request('access_token.company_id', '0');
  110. //终端类型B端、C端、OTO
  111. $terminal_type = request('terminal_type', '');
  112. $product_name = request('product_name', ''); //商品名称
  113. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  114. $limit = request('limit', config('page_num', 10));
  115. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  116. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  117. $start_time_string = request('start_time', '');
  118. $end_time_string = request('end_time', '');
  119. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  120. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  121. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  122. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  123. // 时间条件
  124. $map = [];
  125. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  126. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  127. // 权限判断
  128. if ($is_admin != 1 && $company_id != 0) {
  129. $map[] = ['company_id', '=', $company_id];
  130. } else {
  131. $map[] = ['company_id', '=', $admin_company_id];
  132. }
  133. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  134. $violationProductModel = $violationProductModel->query();
  135. if ($terminal_type) {
  136. $platform = [];
  137. switch ($terminal_type) {
  138. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  139. $platform = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  140. break;
  141. case '2': //C端:美团、拼多多、天猫、京东
  142. $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  143. break;
  144. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  145. $platform = ['0'];
  146. break;
  147. default:
  148. # code...
  149. break;
  150. }
  151. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  152. }
  153. $result = $violationProductModel->where($map)->where('status', 0)
  154. ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
  155. ->groupby('product_name')->paginate($limit);
  156. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  157. }
  158. /**
  159. * 禁止挂网省份统计
  160. * @author 唐远望
  161. * @version 1.0
  162. * @date 2026-02-10
  163. *
  164. */
  165. public function get_violation_province_count(request $request, ViolationProductModel $violationProductModel)
  166. {
  167. $request->scene('get_violation_province_count')->validate();
  168. $admin_company_id = request('admin_company_id', '0');
  169. $company_id = request('access_token.company_id', '0');
  170. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  171. //终端类型B端、C端、OTO
  172. $terminal_type = request('terminal_type', '');
  173. $product_name = request('product_name', ''); //商品名称
  174. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  175. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  176. $start_time_string = request('start_time', '');
  177. $end_time_string = request('end_time', '');
  178. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  179. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  180. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  181. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  182. // 时间条件
  183. $map = [];
  184. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  185. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  186. // 权限判断
  187. if ($is_admin != 1 && $company_id != 0) {
  188. $map[] = ['company_id', '=', $company_id];
  189. } else {
  190. $map[] = ['company_id', '=', $admin_company_id];
  191. }
  192. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  193. // 禁止挂网省份统计
  194. $violationProductModel = $violationProductModel->query();
  195. if ($terminal_type) {
  196. $platform = [];
  197. switch ($terminal_type) {
  198. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  199. $platform = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  200. break;
  201. case '2': //C端:美团、拼多多、天猫、京东
  202. $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  203. break;
  204. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  205. $platform = ['0'];
  206. break;
  207. default:
  208. # code...
  209. break;
  210. }
  211. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  212. }
  213. try {
  214. // 假设 ViolationProductModel 中有 province 字段,表示省份信息
  215. // 查询指定时间范围内的数据,并按 province 分组统计数量
  216. $result = $violationProductModel->where($map)->where('status', 0)
  217. ->select(['province_name', DB::raw('count(province_name) as count')])
  218. ->groupby('province_name')
  219. ->orderby('count', 'desc')
  220. ->get();
  221. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  222. } catch (\Exception $e) {
  223. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  224. }
  225. }
  226. /**
  227. * 禁止挂网城市统计
  228. * @author 唐远望
  229. * @version 1.0
  230. * @date 2026-02-10
  231. *
  232. */
  233. public function get_violation_city_count(request $request, ViolationProductModel $violationProductModel)
  234. {
  235. $request->scene('get_violation_city_count')->validate();
  236. $admin_company_id = request('admin_company_id', '0');
  237. $company_id = request('access_token.company_id', '0');
  238. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  239. //终端类型B端、C端、OTO
  240. $terminal_type = request('terminal_type', '');
  241. $product_name = request('product_name', ''); //商品名称
  242. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  243. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  244. $start_time_string = request('start_time', '');
  245. $end_time_string = request('end_time', '');
  246. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  247. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  248. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  249. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  250. // 时间条件
  251. $map = [];
  252. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  253. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  254. // 权限判断
  255. if ($is_admin != 1 && $company_id != 0) {
  256. $map[] = ['company_id', '=', $company_id];
  257. } else {
  258. $map[] = ['company_id', '=', $admin_company_id];
  259. }
  260. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  261. // 禁止挂网城市统计
  262. $violationProductModel = $violationProductModel->query();
  263. if ($terminal_type) {
  264. $platform = [];
  265. switch ($terminal_type) {
  266. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  267. $platform = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  268. break;
  269. case '2': //C端:美团、拼多多、天猫、京东
  270. $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  271. break;
  272. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  273. $platform = ['0'];
  274. break;
  275. default:
  276. # code...
  277. break;
  278. }
  279. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  280. }
  281. try {
  282. // 假设 ViolationProductModel 中有 city 字段,表示城市信息
  283. // 查询指定时间范围内的数据,并按 city 分组统计数量
  284. $result = $violationProductModel->where($map)->where('status', 0)
  285. ->select(['city_name', DB::raw('count(city_name) as count')])
  286. ->groupby('city_name')
  287. ->orderby('count', 'desc')
  288. ->get();
  289. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  290. } catch (\Exception $e) {
  291. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  292. }
  293. }
  294. /**
  295. * 禁止挂网公司数统计
  296. * @author 唐远望
  297. * @version 1.0
  298. * @date 2026-02-10
  299. *
  300. */
  301. public function get_violation_company_count(request $request, ViolationProductModel $violationProductModel)
  302. {
  303. $request->scene('get_violation_company_count')->validate();
  304. $admin_company_id = request('admin_company_id', '0');
  305. $company_id = request('access_token.company_id', '0');
  306. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  307. //终端类型B端、C端、OTO
  308. $terminal_type = request('terminal_type', '');
  309. $limit = request('limit', config('page_num', 10));
  310. $product_name = request('product_name', ''); //商品名称
  311. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  312. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  313. $start_time_string = request('start_time', '');
  314. $end_time_string = request('end_time', '');
  315. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  316. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  317. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  318. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  319. // 时间条件
  320. $map = [];
  321. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  322. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  323. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  324. // 权限判断
  325. if ($is_admin != 1 && $company_id != 0) {
  326. $map[] = ['company_id', '=', $company_id];
  327. } else {
  328. $map[] = ['company_id', '=', $admin_company_id];
  329. }
  330. $violationProductModel = $violationProductModel->query();
  331. if ($terminal_type) {
  332. $platform = [];
  333. switch ($terminal_type) {
  334. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  335. $platform = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  336. break;
  337. case '2': //C端:美团、拼多多、天猫、京东
  338. $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  339. break;
  340. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  341. $platform = ['0'];
  342. break;
  343. default:
  344. # code...
  345. break;
  346. }
  347. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  348. }
  349. $result = $violationProductModel->where($map)->where('status', 0)
  350. ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
  351. ->paginate($limit);
  352. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  353. }
  354. /*
  355. * 低价违规商品数统计
  356. * @author 唐远望
  357. * @version 1.0
  358. * @date 2026-02-10
  359. *
  360. */
  361. public function get_low_price_product_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  362. {
  363. $request->scene('get_low_price_product_count')->validate();
  364. $admin_company_id = request('admin_company_id', '0');
  365. $company_id = request('access_token.company_id', '0');
  366. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  367. //终端类型B端、C端、OTO
  368. $terminal_type = request('terminal_type', '');
  369. $limit = request('limit', config('page_num', 10));
  370. $product_name = request('product_name', ''); //商品名称
  371. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  372. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  373. $start_time_string = request('start_time', '');
  374. $end_time_string = request('end_time', '');
  375. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  376. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  377. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  378. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  379. // 时间条件
  380. $map = [];
  381. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  382. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  383. // 权限判断
  384. if ($is_admin != 1 && $company_id != 0) {
  385. $map[] = ['company_id', '=', $company_id];
  386. } else {
  387. $map[] = ['company_id', '=', $admin_company_id];
  388. }
  389. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  390. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  391. if ($terminal_type) {
  392. $platform = [];
  393. switch ($terminal_type) {
  394. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  395. $platform = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  396. break;
  397. case '2': //C端:美团、拼多多、天猫、京东
  398. $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  399. break;
  400. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  401. $platform = ['0'];
  402. break;
  403. default:
  404. # code...
  405. break;
  406. }
  407. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  408. }
  409. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  410. ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
  411. ->groupby('product_name')->paginate($limit);
  412. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  413. }
  414. /*
  415. * 低价违规公司数统计
  416. * @author 唐远望
  417. * @version 1.0
  418. * @date 2026-02-10
  419. *
  420. */
  421. public function get_low_price_company_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  422. {
  423. $request->scene('get_low_price_company_count')->validate();
  424. $admin_company_id = request('admin_company_id', '0');
  425. $company_id = request('access_token.company_id', '0');
  426. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  427. //终端类型B端、C端、OTO
  428. $terminal_type = request('terminal_type', '');
  429. $limit = request('limit', config('page_num', 10));
  430. $product_name = request('product_name', ''); //商品名称
  431. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  432. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  433. $start_time_string = request('start_time', '');
  434. $end_time_string = request('end_time', '');
  435. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  436. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  437. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  438. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  439. // 时间条件
  440. $map = [];
  441. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  442. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  443. // 权限判断
  444. if ($is_admin != 1 && $company_id != 0) {
  445. $map[] = ['company_id', '=', $company_id];
  446. } else {
  447. $map[] = ['company_id', '=', $admin_company_id];
  448. }
  449. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  450. if ($terminal_type) {
  451. $platform = [];
  452. switch ($terminal_type) {
  453. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  454. $platform = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  455. break;
  456. case '2': //C端:美团、拼多多、天猫、京东
  457. $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  458. break;
  459. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  460. $platform = ['0'];
  461. break;
  462. default:
  463. # code...
  464. break;
  465. }
  466. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  467. }
  468. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  469. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  470. ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
  471. ->paginate($limit);
  472. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  473. }
  474. /**
  475. * 低价挂网省份统计
  476. * @author 唐远望
  477. * @version 1.0
  478. * @date 2026-02-10
  479. *
  480. */
  481. public function get_low_price_province_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  482. {
  483. $request->scene('get_low_price_province_count')->validate();
  484. $admin_company_id = request('admin_company_id', '0');
  485. $company_id = request('access_token.company_id', '0');
  486. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  487. //终端类型B端、C端、OTO
  488. $terminal_type = request('terminal_type', '');
  489. $product_name = request('product_name', ''); //商品名称
  490. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  491. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  492. $start_time_string = request('start_time', '');
  493. $end_time_string = request('end_time', '');
  494. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  495. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  496. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  497. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  498. // 时间条件
  499. $map = [];
  500. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  501. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  502. // 权限判断
  503. if ($is_admin != 1 && $company_id != 0) {
  504. $map[] = ['company_id', '=', $company_id];
  505. } else {
  506. $map[] = ['company_id', '=', $admin_company_id];
  507. }
  508. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  509. // 禁止挂网省份统计
  510. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  511. if ($terminal_type) {
  512. $platform = [];
  513. switch ($terminal_type) {
  514. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  515. $platform = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  516. break;
  517. case '2': //C端:美团、拼多多、天猫、京东
  518. $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  519. break;
  520. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  521. $platform = ['0'];
  522. break;
  523. default:
  524. # code...
  525. break;
  526. }
  527. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  528. }
  529. try {
  530. // 假设 LowPriceGoodsModel 中有 province 字段,表示省份信息
  531. // 查询指定时间范围内的数据,并按 province 分组统计数量
  532. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  533. ->select(['province_name', DB::raw('count(province_name) as count')])
  534. ->groupby('province_name')
  535. ->orderby('count', 'desc')
  536. ->get();
  537. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  538. } catch (\Exception $e) {
  539. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  540. }
  541. }
  542. /**
  543. * 低价挂网城市统计
  544. * @author 唐远望
  545. * @version 1.0
  546. * @date 2026-02-10
  547. *
  548. */
  549. public function get_low_price_city_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  550. {
  551. $request->scene('get_low_price_city_count')->validate();
  552. $admin_company_id = request('admin_company_id', '0');
  553. $company_id = request('access_token.company_id', '0');
  554. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  555. //终端类型B端、C端、OTO
  556. $terminal_type = request('terminal_type', '');
  557. $product_name = request('product_name', ''); //商品名称
  558. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  559. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  560. $start_time_string = request('start_time', '');
  561. $end_time_string = request('end_time', '');
  562. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  563. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  564. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  565. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  566. // 时间条件
  567. $map = [];
  568. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  569. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  570. // 权限判断
  571. if ($is_admin != 1 && $company_id != 0) {
  572. $map[] = ['company_id', '=', $company_id];
  573. } else {
  574. $map[] = ['company_id', '=', $admin_company_id];
  575. }
  576. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  577. // 禁止挂网城市统计
  578. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  579. if ($terminal_type) {
  580. $platform = [];
  581. switch ($terminal_type) {
  582. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  583. $platform = ['0','5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  584. break;
  585. case '2': //C端:美团、拼多多、天猫、京东
  586. $platform = ['0','1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  587. break;
  588. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  589. $platform = ['0'];
  590. break;
  591. default:
  592. # code...
  593. break;
  594. }
  595. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  596. }
  597. try {
  598. // 假设 LowPriceGoodsModel 中有 city 字段,表示城市信息
  599. // 查询指定时间范围内的数据,并按 city 分组统计数量
  600. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  601. ->select(['city_name', DB::raw('count(city_name) as count')])
  602. ->groupby('city_name')
  603. ->orderby('count', 'desc')
  604. ->get();
  605. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  606. } catch (\Exception $e) {
  607. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  608. }
  609. }
  610. }