BasicPanel.php 34 KB

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