BasicPanel.php 35 KB

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