BasicPanel.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  34. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  35. $start_time_string = request('start_time', '');
  36. $end_time_string = request('end_time', '');
  37. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  38. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  39. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  40. if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  41. // 时间条件
  42. $map = [];
  43. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  44. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  45. // 统计挂网商品数量=低价挂网商品数量(去重)+ 禁止挂网商品数量(去重)
  46. $lowPriceGoodsModel = $lowPriceGoodsModel->query();
  47. $violationProductModel = $violationProductModel->query();
  48. if ($is_admin != 1 && $company_id != 0) {
  49. $lowPriceGoodsModel = $lowPriceGoodsModel->where('company_id', $company_id);
  50. $violationProductModel = $violationProductModel->where('company_id', $company_id);
  51. } else {
  52. $lowPriceGoodsModel = $lowPriceGoodsModel->where('company_id', $admin_company_id);
  53. $violationProductModel = $violationProductModel->where('company_id', $admin_company_id);
  54. }
  55. // 低价挂网商品数量查询
  56. $lowPriceGoodsCount = $lowPriceGoodsModel->where($map)
  57. ->where('status', 0)
  58. ->groupBy('product_name')
  59. ->count(DB::raw('DISTINCT product_name'));
  60. // 禁止挂网商品数量查询
  61. $violationProductCount = $violationProductModel->where($map)
  62. ->where('status', 0)
  63. ->groupBy('product_name')
  64. ->count(DB::raw('DISTINCT product_name'));
  65. // 违规店铺数量查询
  66. $violationStoreCount = $violationStoreModel->where($map)
  67. ->where('status', 0)
  68. ->groupBy('company_name')
  69. ->count(DB::raw('DISTINCT company_name'));
  70. //获取终端类型B端、C端、OTO,配置品规数量
  71. $collect_b_product_count = $productModel->whereIn('platform', ['5', '6', '7', '8', '9', '10'])->where('status', 0)->count();
  72. $collect_c_product_count = $productModel->whereIn('platform', ['1', '2', '3', '4'])->where('status', 0)->count();
  73. $collect_oto_product_count = $productModel->whereIn('platform', [])->where('status', 0)->count();
  74. // 所有终端品规数量
  75. $collect_totle_product_count = $collect_b_product_count + $collect_c_product_count + $collect_oto_product_count;
  76. $result_data = [
  77. 'low_price_goods_count' => $lowPriceGoodsCount, // 低价挂网商品数量
  78. 'violation_product_count' => $violationProductCount, // 禁止挂网商品数量
  79. 'violation_store_count' => $violationStoreCount, // 违规店铺数量
  80. 'totle_product_count' => $lowPriceGoodsCount + $violationProductCount, // 总商品数量
  81. 'collect_b_product_count' => $collect_b_product_count, // B端品规数量
  82. 'collect_c_product_count' => $collect_c_product_count, // C端品规数量
  83. 'collect_oto_product_count' => $collect_oto_product_count, // OTO品规数量
  84. 'collect_totle_product_count' => $collect_totle_product_count, // 所有终端品规数量
  85. ];
  86. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result_data]);
  87. }
  88. /**
  89. * 禁止挂网商品数统计
  90. * @author 唐远望
  91. * @version 1.0
  92. * @date 2026-02-10
  93. *
  94. */
  95. public function get_violation_product_count(request $request, ViolationProductModel $violationProductModel)
  96. {
  97. $request->scene('get_violation_product_count')->validate();
  98. $admin_company_id = request('admin_company_id', '0');
  99. //终端类型B端、C端、OTO
  100. $terminal_type = request('terminal_type', '');
  101. $company_id = request('access_token.company_id', '0');
  102. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  103. $limit = request('limit', config('page_num', 10));
  104. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  105. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  106. $start_time_string = request('start_time', '');
  107. $end_time_string = request('end_time', '');
  108. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  109. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  110. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  111. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  112. // 时间条件
  113. $map = [];
  114. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  115. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  116. // 权限判断
  117. if ($is_admin != 1 && $company_id != 0) {
  118. $map[] = ['company_id', '=', $company_id];
  119. } else {
  120. $map[] = ['company_id', '=', $admin_company_id];
  121. }
  122. $violationProductModel = $violationProductModel->query();
  123. if ($terminal_type) {
  124. $platform = [];
  125. switch ($terminal_type) {
  126. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  127. $platform = ['5', '6', '7', '8', '9', '10']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  128. break;
  129. case '2': //C端:美团、拼多多、天猫、京东
  130. $platform = ['1', '2', '3', '4']; //平台0=全部,1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药
  131. break;
  132. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  133. $platform = [];
  134. break;
  135. default:
  136. # code...
  137. break;
  138. }
  139. $violationProductModel = $violationProductModel->whereIn('platform_id', $platform);
  140. }
  141. $result = $violationProductModel->where($map)->where('status', 0)
  142. ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
  143. ->groupby('product_name')->paginate($limit);
  144. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  145. }
  146. /**
  147. * 禁止挂网公司数统计
  148. * @author 唐远望
  149. * @version 1.0
  150. * @date 2026-02-10
  151. *
  152. */
  153. public function get_violation_company_count(request $request, ViolationProductModel $violationProductModel)
  154. {
  155. $request->scene('get_violation_company_count')->validate();
  156. $admin_company_id = request('admin_company_id', '0');
  157. $company_id = request('access_token.company_id', '0');
  158. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  159. $limit = request('limit', config('page_num', 10));
  160. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  161. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  162. $start_time_string = request('start_time', '');
  163. $end_time_string = request('end_time', '');
  164. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  165. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  166. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  167. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  168. // 时间条件
  169. $map = [];
  170. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  171. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  172. // 权限判断
  173. if ($is_admin != 1 && $company_id != 0) {
  174. $map[] = ['company_id', '=', $company_id];
  175. } else {
  176. $map[] = ['company_id', '=', $admin_company_id];
  177. }
  178. $result = $violationProductModel->where($map)->where('status', 0)
  179. ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
  180. ->paginate($limit);
  181. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  182. }
  183. /*
  184. * 低价违规商品数统计
  185. * @author 唐远望
  186. * @version 1.0
  187. * @date 2026-02-10
  188. *
  189. */
  190. public function get_low_price_product_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  191. {
  192. $request->scene('get_low_price_product_count')->validate();
  193. $admin_company_id = request('admin_company_id', '0');
  194. $company_id = request('access_token.company_id', '0');
  195. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  196. $limit = request('limit', config('page_num', 10));
  197. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  198. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  199. $start_time_string = request('start_time', '');
  200. $end_time_string = request('end_time', '');
  201. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  202. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  203. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  204. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  205. // 时间条件
  206. $map = [];
  207. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  208. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  209. // 权限判断
  210. if ($is_admin != 1 && $company_id != 0) {
  211. $map[] = ['company_id', '=', $company_id];
  212. } else {
  213. $map[] = ['company_id', '=', $admin_company_id];
  214. }
  215. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  216. ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
  217. ->groupby('product_name')->paginate($limit);
  218. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  219. }
  220. /*
  221. * 低价违规公司数统计
  222. * @author 唐远望
  223. * @version 1.0
  224. * @date 2026-02-10
  225. *
  226. */
  227. public function get_low_price_company_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  228. {
  229. $request->scene('get_low_price_company_count')->validate();
  230. $admin_company_id = request('admin_company_id', '0');
  231. $company_id = request('access_token.company_id', '0');
  232. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  233. $limit = request('limit', config('page_num', 10));
  234. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  235. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  236. $start_time_string = request('start_time', '');
  237. $end_time_string = request('end_time', '');
  238. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  239. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  240. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  241. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  242. // 时间条件
  243. $map = [];
  244. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  245. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  246. // 权限判断
  247. if ($is_admin != 1 && $company_id != 0) {
  248. $map[] = ['company_id', '=', $company_id];
  249. } else {
  250. $map[] = ['company_id', '=', $admin_company_id];
  251. }
  252. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  253. ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
  254. ->paginate($limit);
  255. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  256. }
  257. }