BasicPanel.php 36 KB

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