BasicPanel.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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', $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', $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', $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. //终端类型B端、C端、OTO
  300. $terminal_type = request('terminal_type', '');
  301. $limit = request('limit', config('page_num', 10));
  302. $product_name = request('product_name', ''); //商品名称
  303. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  304. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  305. $start_time_string = request('start_time', '');
  306. $end_time_string = request('end_time', '');
  307. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  308. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  309. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  310. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  311. // 时间条件
  312. $map = [];
  313. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  314. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  315. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  316. // 权限判断
  317. if ($is_admin != 1 && $company_id != 0) {
  318. $map[] = ['company_id', '=', $company_id];
  319. } else {
  320. $map[] = ['company_id', '=', $admin_company_id];
  321. }
  322. $violationProductModel = $violationProductModel->query();
  323. if ($terminal_type) {
  324. $platform = [];
  325. switch ($terminal_type) {
  326. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  327. $platform = ['5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  328. break;
  329. case '2': //C端:美团、拼多多、天猫、京东
  330. $platform = ['1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  331. break;
  332. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  333. $platform = [];
  334. break;
  335. default:
  336. # code...
  337. break;
  338. }
  339. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  340. }
  341. $result = $violationProductModel->where($map)->where('status', 0)
  342. ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
  343. ->paginate($limit);
  344. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  345. }
  346. /*
  347. * 低价违规商品数统计
  348. * @author 唐远望
  349. * @version 1.0
  350. * @date 2026-02-10
  351. *
  352. */
  353. public function get_low_price_product_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  354. {
  355. $request->scene('get_low_price_product_count')->validate();
  356. $admin_company_id = request('admin_company_id', '0');
  357. $company_id = request('access_token.company_id', '0');
  358. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  359. //终端类型B端、C端、OTO
  360. $terminal_type = request('terminal_type', '');
  361. $limit = request('limit', config('page_num', 10));
  362. $product_name = request('product_name', ''); //商品名称
  363. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  364. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  365. $start_time_string = request('start_time', '');
  366. $end_time_string = request('end_time', '');
  367. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  368. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  369. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  370. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  371. // 时间条件
  372. $map = [];
  373. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  374. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  375. // 权限判断
  376. if ($is_admin != 1 && $company_id != 0) {
  377. $map[] = ['company_id', '=', $company_id];
  378. } else {
  379. $map[] = ['company_id', '=', $admin_company_id];
  380. }
  381. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  382. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  383. if ($terminal_type) {
  384. $platform = [];
  385. switch ($terminal_type) {
  386. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  387. $platform = ['5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  388. break;
  389. case '2': //C端:美团、拼多多、天猫、京东
  390. $platform = ['1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  391. break;
  392. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  393. $platform = [];
  394. break;
  395. default:
  396. # code...
  397. break;
  398. }
  399. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  400. }
  401. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  402. ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
  403. ->groupby('product_name')->paginate($limit);
  404. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  405. }
  406. /*
  407. * 低价违规公司数统计
  408. * @author 唐远望
  409. * @version 1.0
  410. * @date 2026-02-10
  411. *
  412. */
  413. public function get_low_price_company_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  414. {
  415. $request->scene('get_low_price_company_count')->validate();
  416. $admin_company_id = request('admin_company_id', '0');
  417. $company_id = request('access_token.company_id', '0');
  418. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  419. //终端类型B端、C端、OTO
  420. $terminal_type = request('terminal_type', '');
  421. $limit = request('limit', config('page_num', 10));
  422. $product_name = request('product_name', ''); //商品名称
  423. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  424. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  425. $start_time_string = request('start_time', '');
  426. $end_time_string = request('end_time', '');
  427. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  428. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  429. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  430. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  431. // 时间条件
  432. $map = [];
  433. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  434. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  435. // 权限判断
  436. if ($is_admin != 1 && $company_id != 0) {
  437. $map[] = ['company_id', '=', $company_id];
  438. } else {
  439. $map[] = ['company_id', '=', $admin_company_id];
  440. }
  441. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  442. if ($terminal_type) {
  443. $platform = [];
  444. switch ($terminal_type) {
  445. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  446. $platform = ['5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  447. break;
  448. case '2': //C端:美团、拼多多、天猫、京东
  449. $platform = ['1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  450. break;
  451. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  452. $platform = [];
  453. break;
  454. default:
  455. # code...
  456. break;
  457. }
  458. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  459. }
  460. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  461. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  462. ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
  463. ->paginate($limit);
  464. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  465. }
  466. /**
  467. * 低价挂网省份统计
  468. * @author 唐远望
  469. * @version 1.0
  470. * @date 2026-02-10
  471. *
  472. */
  473. public function get_low_price_province_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  474. {
  475. $request->scene('get_low_price_province_count')->validate();
  476. $admin_company_id = request('admin_company_id', '0');
  477. $company_id = request('access_token.company_id', '0');
  478. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  479. //终端类型B端、C端、OTO
  480. $terminal_type = request('terminal_type', '');
  481. $product_name = request('product_name', ''); //商品名称
  482. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  483. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  484. $start_time_string = request('start_time', '');
  485. $end_time_string = request('end_time', '');
  486. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  487. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  488. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  489. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  490. // 时间条件
  491. $map = [];
  492. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  493. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  494. // 权限判断
  495. if ($is_admin != 1 && $company_id != 0) {
  496. $map[] = ['company_id', '=', $company_id];
  497. } else {
  498. $map[] = ['company_id', '=', $admin_company_id];
  499. }
  500. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  501. // 禁止挂网省份统计
  502. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  503. if ($terminal_type) {
  504. $platform = [];
  505. switch ($terminal_type) {
  506. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  507. $platform = ['5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  508. break;
  509. case '2': //C端:美团、拼多多、天猫、京东
  510. $platform = ['1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  511. break;
  512. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  513. $platform = [];
  514. break;
  515. default:
  516. # code...
  517. break;
  518. }
  519. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  520. }
  521. try {
  522. // 假设 LowPriceGoodsModel 中有 province 字段,表示省份信息
  523. // 查询指定时间范围内的数据,并按 province 分组统计数量
  524. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  525. ->select(['province_name', DB::raw('count(province_name) as count')])
  526. ->groupby('province_name')
  527. ->orderby('count', 'desc')
  528. ->get();
  529. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  530. } catch (\Exception $e) {
  531. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  532. }
  533. }
  534. /**
  535. * 低价挂网城市统计
  536. * @author 唐远望
  537. * @version 1.0
  538. * @date 2026-02-10
  539. *
  540. */
  541. public function get_low_price_city_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  542. {
  543. $request->scene('get_low_price_city_count')->validate();
  544. $admin_company_id = request('admin_company_id', '0');
  545. $company_id = request('access_token.company_id', '0');
  546. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  547. //终端类型B端、C端、OTO
  548. $terminal_type = request('terminal_type', '');
  549. $product_name = request('product_name', ''); //商品名称
  550. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  551. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  552. $start_time_string = request('start_time', '');
  553. $end_time_string = request('end_time', '');
  554. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  555. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  556. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  557. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  558. // 时间条件
  559. $map = [];
  560. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  561. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  562. // 权限判断
  563. if ($is_admin != 1 && $company_id != 0) {
  564. $map[] = ['company_id', '=', $company_id];
  565. } else {
  566. $map[] = ['company_id', '=', $admin_company_id];
  567. }
  568. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  569. // 禁止挂网城市统计
  570. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  571. if ($terminal_type) {
  572. $platform = [];
  573. switch ($terminal_type) {
  574. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  575. $platform = ['5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  576. break;
  577. case '2': //C端:美团、拼多多、天猫、京东
  578. $platform = ['1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  579. break;
  580. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  581. $platform = [];
  582. break;
  583. default:
  584. # code...
  585. break;
  586. }
  587. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  588. }
  589. try {
  590. // 假设 LowPriceGoodsModel 中有 city 字段,表示城市信息
  591. // 查询指定时间范围内的数据,并按 city 分组统计数量
  592. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  593. ->select(['city_name', DB::raw('count(city_name) as count')])
  594. ->groupby('city_name')
  595. ->orderby('count', 'desc')
  596. ->get();
  597. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  598. } catch (\Exception $e) {
  599. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  600. }
  601. }
  602. }