BasicPanel.php 30 KB

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