BasicPanel.php 35 KB

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