BasicPanel.php 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557
  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. $productModel = new ProductModel();
  82. $productModel_map = [];
  83. if ($start_time) $productModel_map[] = ['insert_time', '>=', $start_time];
  84. if ($end_time) $productModel_map[] = ['insert_time', '<=', $end_time];
  85. if ($is_admin != 1 && $company_id != 0) {
  86. $productModel = $productModel->where('company_id', $company_id);
  87. } else {
  88. $productModel = $productModel->where('company_id', $admin_company_id);
  89. }
  90. $productNames = $productModel
  91. ->where(function ($query) {
  92. $platforms = ['0', '5', '6', '7', '8', '9', '10'];
  93. foreach ($platforms as $platform) {
  94. $query->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
  95. }
  96. })
  97. ->where('status', 0)
  98. ->where($productModel_map)
  99. ->distinct('product_name')
  100. ->pluck('product_name');
  101. $collect_b_product_count = $productModel
  102. ->whereIn('product_name', $productNames)
  103. ->where('status', 0)
  104. ->where($productModel_map)
  105. ->sum('product_specs_number');
  106. $productModel = new ProductModel();
  107. $productModel_map = [];
  108. if ($start_time) $productModel_map[] = ['insert_time', '>=', $start_time];
  109. if ($end_time) $productModel_map[] = ['insert_time', '<=', $end_time];
  110. if ($is_admin != 1 && $company_id != 0) {
  111. $productModel = $productModel->where('company_id', $company_id);
  112. } else {
  113. $productModel = $productModel->where('company_id', $admin_company_id);
  114. }
  115. $productNames = $productModel
  116. ->where(function ($query) {
  117. $platforms = ['0', '1', '2', '3', '4','11'];//C端:美团、拼多多、天猫、京东、药房网
  118. foreach ($platforms as $platform) {
  119. $query->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
  120. }
  121. })
  122. ->where('status', 0)
  123. ->where($productModel_map)
  124. ->distinct('product_name')
  125. ->pluck('product_name');
  126. $collect_c_product_count = $productModel
  127. ->whereIn('product_name', $productNames)
  128. ->where('status', 0)
  129. ->where($productModel_map)
  130. ->sum('product_specs_number');
  131. $productModel = new ProductModel();
  132. $productModel_map = [];
  133. if ($start_time) $productModel_map[] = ['insert_time', '>=', $start_time];
  134. if ($end_time) $productModel_map[] = ['insert_time', '<=', $end_time];
  135. if ($is_admin != 1 && $company_id != 0) {
  136. $productModel = $productModel->where('company_id', $company_id);
  137. } else {
  138. $productModel = $productModel->where('company_id', $admin_company_id);
  139. }
  140. $productNames = $productModel
  141. ->where(function ($query) {
  142. $platforms = ['0'];
  143. foreach ($platforms as $platform) {
  144. $query->orWhereRaw("FIND_IN_SET(?, platform)", [$platform]);
  145. }
  146. })
  147. ->where('status', 0)
  148. ->where($productModel_map)
  149. ->distinct('product_name')
  150. ->pluck('product_name');
  151. $collect_oto_product_count = $productModel
  152. ->whereIn('product_name', $productNames)
  153. ->where('status', 0)
  154. ->where($productModel_map)
  155. ->sum('product_specs_number');
  156. // 所有终端品规数量
  157. $collect_totle_product_count = $collect_b_product_count + $collect_c_product_count + $collect_oto_product_count;
  158. $result_data = [
  159. 'low_price_goods_count' => $lowPriceGoodsCount, // 低价挂网商品数量
  160. 'violation_product_count' => $violationProductCount, // 禁止挂网商品数量
  161. 'violation_store_count' => $violationStoreCount, // 违规店铺数量
  162. 'totle_product_count' => $lowPriceGoodsCount + $violationProductCount, // 总商品数量
  163. 'collect_b_product_count' => $collect_b_product_count, // B端品规数量
  164. 'collect_c_product_count' => $collect_c_product_count, // C端品规数量
  165. 'collect_oto_product_count' => $collect_oto_product_count, // OTO品规数量
  166. 'collect_totle_product_count' => $collect_totle_product_count, // 所有终端品规数量
  167. ];
  168. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result_data]);
  169. }
  170. /**
  171. * 禁止挂网商品数统计
  172. * @author 唐远望
  173. * @version 1.0
  174. * @date 2026-02-10
  175. *
  176. */
  177. public function get_violation_product_count(request $request, ViolationProductModel $violationProductModel)
  178. {
  179. $request->scene('get_violation_product_count')->validate();
  180. $admin_company_id = request('admin_company_id', '0');
  181. $company_id = request('access_token.company_id', '0');
  182. //终端类型B端、C端、OTO
  183. $terminal_type = request('terminal_type', '');
  184. $product_name = request('product_name', ''); //商品名称
  185. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  186. $limit = request('limit', config('page_num', 10));
  187. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  188. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  189. $start_time_string = request('start_time', '');
  190. $end_time_string = request('end_time', '');
  191. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  192. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  193. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  194. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  195. // 时间条件
  196. $map = [];
  197. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  198. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  199. // 权限判断
  200. if ($is_admin != 1 && $company_id != 0) {
  201. $map[] = ['company_id', '=', $company_id];
  202. } else {
  203. $map[] = ['company_id', '=', $admin_company_id];
  204. }
  205. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  206. $violationProductModel = $violationProductModel->query();
  207. if ($terminal_type) {
  208. $platform = [];
  209. switch ($terminal_type) {
  210. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  211. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  212. break;
  213. case '2': //C端:美团、拼多多、天猫、京东、药房网
  214. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  215. break;
  216. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  217. $platform = ['0'];
  218. break;
  219. default:
  220. # code...
  221. break;
  222. }
  223. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  224. }
  225. $result = $violationProductModel->where($map)->where('status', 0)
  226. ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
  227. ->groupby('product_name')->paginate($limit);
  228. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  229. }
  230. /**
  231. * 禁止挂网省份统计
  232. * @author 唐远望
  233. * @version 1.0
  234. * @date 2026-02-10
  235. *
  236. */
  237. public function get_violation_province_count(request $request, ViolationProductModel $violationProductModel)
  238. {
  239. $request->scene('get_violation_province_count')->validate();
  240. $admin_company_id = request('admin_company_id', '0');
  241. $company_id = request('access_token.company_id', '0');
  242. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  243. //终端类型B端、C端、OTO
  244. $terminal_type = request('terminal_type', '');
  245. $product_name = request('product_name', ''); //商品名称
  246. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  247. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  248. $start_time_string = request('start_time', '');
  249. $end_time_string = request('end_time', '');
  250. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  251. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  252. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  253. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  254. // 时间条件
  255. $map = [];
  256. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  257. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  258. // 权限判断
  259. if ($is_admin != 1 && $company_id != 0) {
  260. $map[] = ['company_id', '=', $company_id];
  261. } else {
  262. $map[] = ['company_id', '=', $admin_company_id];
  263. }
  264. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  265. // 禁止挂网省份统计
  266. $violationProductModel = $violationProductModel->query();
  267. if ($terminal_type) {
  268. $platform = [];
  269. switch ($terminal_type) {
  270. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  271. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  272. break;
  273. case '2': //C端:美团、拼多多、天猫、京东、药房网
  274. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  275. break;
  276. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  277. $platform = ['0'];
  278. break;
  279. default:
  280. # code...
  281. break;
  282. }
  283. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  284. }
  285. try {
  286. // 假设 ViolationProductModel 中有 province 字段,表示省份信息
  287. // 查询指定时间范围内的数据,并按 province 分组统计数量
  288. $result = $violationProductModel->where($map)->where('status', 0)
  289. ->select(['province_name', DB::raw('count(province_name) as count')])
  290. ->groupby('province_name')
  291. ->orderby('count', 'desc')
  292. ->get()->toArray();
  293. $province_totle_count = 0;
  294. if (!empty($result)) {
  295. $province_totle_count = array_sum(array_column($result, 'count'));
  296. //计算占比
  297. foreach ($result as $key => $value) {
  298. $result[$key]['percent'] = round(($value['count'] / $province_totle_count) * 100, 2);
  299. }
  300. }
  301. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  302. } catch (\Exception $e) {
  303. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  304. }
  305. }
  306. /**
  307. * 禁止挂网城市统计
  308. * @author 唐远望
  309. * @version 1.0
  310. * @date 2026-02-10
  311. *
  312. */
  313. public function get_violation_city_count(request $request, ViolationProductModel $violationProductModel)
  314. {
  315. $request->scene('get_violation_city_count')->validate();
  316. $admin_company_id = request('admin_company_id', '0');
  317. $company_id = request('access_token.company_id', '0');
  318. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  319. //终端类型B端、C端、OTO
  320. $province_id = request('province_id', ''); //省份ID
  321. $terminal_type = request('terminal_type', '');
  322. $product_name = request('product_name', ''); //商品名称
  323. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  324. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  325. $start_time_string = request('start_time', '');
  326. $end_time_string = request('end_time', '');
  327. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  328. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  329. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  330. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  331. // 时间条件
  332. $map = [];
  333. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  334. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  335. // 权限判断
  336. if ($is_admin != 1 && $company_id != 0) {
  337. $map[] = ['company_id', '=', $company_id];
  338. } else {
  339. $map[] = ['company_id', '=', $admin_company_id];
  340. }
  341. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  342. if ($province_id) $map[] = ['province_id', '=', $province_id];
  343. // 禁止挂网城市统计
  344. $violationProductModel = $violationProductModel->query();
  345. if ($terminal_type) {
  346. $platform = [];
  347. switch ($terminal_type) {
  348. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  349. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  350. break;
  351. case '2': //C端:美团、拼多多、天猫、京东、药房网
  352. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  353. break;
  354. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  355. $platform = ['0'];
  356. break;
  357. default:
  358. # code...
  359. break;
  360. }
  361. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  362. }
  363. try {
  364. // 假设 ViolationProductModel 中有 city 字段,表示城市信息
  365. // 查询指定时间范围内的数据,并按 city 分组统计数量
  366. $result = $violationProductModel->where($map)->where('status', 0)
  367. ->select(['city_name', DB::raw('count(city_name) as count')])
  368. ->groupby('city_name')
  369. ->orderby('count', 'desc')
  370. ->get()->toArray();
  371. $city_totle_count = 0;
  372. if (!empty($result)) {
  373. $city_totle_count = array_sum(array_column($result, 'count'));
  374. //计算占比
  375. foreach ($result as $key => $value) {
  376. $result[$key]['percent'] = round(($value['count'] / $city_totle_count) * 100, 2);
  377. }
  378. }
  379. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  380. } catch (\Exception $e) {
  381. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  382. }
  383. }
  384. /**
  385. * 禁止挂网公司数统计
  386. * @author 唐远望
  387. * @version 1.0
  388. * @date 2026-02-10
  389. *
  390. */
  391. public function get_violation_company_count(request $request, ViolationProductModel $violationProductModel)
  392. {
  393. $request->scene('get_violation_company_count')->validate();
  394. $admin_company_id = request('admin_company_id', '0');
  395. $company_id = request('access_token.company_id', '0');
  396. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  397. //终端类型B端、C端、OTO
  398. $terminal_type = request('terminal_type', '');
  399. $limit = request('limit', config('page_num', 10));
  400. $product_name = request('product_name', ''); //商品名称
  401. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  402. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  403. $start_time_string = request('start_time', '');
  404. $end_time_string = request('end_time', '');
  405. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  406. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  407. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  408. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  409. // 时间条件
  410. $map = [];
  411. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  412. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  413. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  414. // 权限判断
  415. if ($is_admin != 1 && $company_id != 0) {
  416. $map[] = ['company_id', '=', $company_id];
  417. } else {
  418. $map[] = ['company_id', '=', $admin_company_id];
  419. }
  420. $violationProductModel = $violationProductModel->query();
  421. if ($terminal_type) {
  422. $platform = [];
  423. switch ($terminal_type) {
  424. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  425. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  426. break;
  427. case '2': //C端:美团、拼多多、天猫、京东、药房网
  428. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  429. break;
  430. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  431. $platform = ['0'];
  432. break;
  433. default:
  434. # code...
  435. break;
  436. }
  437. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  438. }
  439. $result = $violationProductModel->where($map)->where('status', 0)
  440. ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
  441. ->paginate($limit);
  442. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  443. }
  444. /*
  445. * 低价违规商品数统计
  446. * @author 唐远望
  447. * @version 1.0
  448. * @date 2026-02-10
  449. *
  450. */
  451. public function get_low_price_product_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  452. {
  453. $request->scene('get_low_price_product_count')->validate();
  454. $admin_company_id = request('admin_company_id', '0');
  455. $company_id = request('access_token.company_id', '0');
  456. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  457. //终端类型B端、C端、OTO
  458. $terminal_type = request('terminal_type', '');
  459. $limit = request('limit', config('page_num', 10));
  460. $product_name = request('product_name', ''); //商品名称
  461. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  462. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  463. $start_time_string = request('start_time', '');
  464. $end_time_string = request('end_time', '');
  465. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  466. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  467. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  468. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  469. // 时间条件
  470. $map = [];
  471. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  472. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  473. // 权限判断
  474. if ($is_admin != 1 && $company_id != 0) {
  475. $map[] = ['company_id', '=', $company_id];
  476. } else {
  477. $map[] = ['company_id', '=', $admin_company_id];
  478. }
  479. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  480. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  481. if ($terminal_type) {
  482. $platform = [];
  483. switch ($terminal_type) {
  484. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  485. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  486. break;
  487. case '2': //C端:美团、拼多多、天猫、京东、药房网
  488. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  489. break;
  490. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  491. $platform = ['0'];
  492. break;
  493. default:
  494. # code...
  495. break;
  496. }
  497. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  498. }
  499. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  500. ->select(['product_name', DB::raw('count(product_name) as count')])->distinct('product_name')->orderby('count', 'desc')
  501. ->groupby('product_name')->paginate($limit);
  502. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  503. }
  504. /*
  505. * 低价违规公司数统计
  506. * @author 唐远望
  507. * @version 1.0
  508. * @date 2026-02-10
  509. *
  510. */
  511. public function get_low_price_company_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  512. {
  513. $request->scene('get_low_price_company_count')->validate();
  514. $admin_company_id = request('admin_company_id', '0');
  515. $company_id = request('access_token.company_id', '0');
  516. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  517. //终端类型B端、C端、OTO
  518. $terminal_type = request('terminal_type', '');
  519. $limit = request('limit', config('page_num', 10));
  520. $product_name = request('product_name', ''); //商品名称
  521. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  522. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  523. $start_time_string = request('start_time', '');
  524. $end_time_string = request('end_time', '');
  525. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  526. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  527. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  528. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  529. // 时间条件
  530. $map = [];
  531. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  532. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  533. // 权限判断
  534. if ($is_admin != 1 && $company_id != 0) {
  535. $map[] = ['company_id', '=', $company_id];
  536. } else {
  537. $map[] = ['company_id', '=', $admin_company_id];
  538. }
  539. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  540. if ($terminal_type) {
  541. $platform = [];
  542. switch ($terminal_type) {
  543. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  544. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  545. break;
  546. case '2': //C端:美团、拼多多、天猫、京东、药房网
  547. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  548. break;
  549. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  550. $platform = ['0'];
  551. break;
  552. default:
  553. # code...
  554. break;
  555. }
  556. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  557. }
  558. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  559. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  560. ->select(['company_name', DB::raw('count(company_name) as count')])->groupby('company_name')->orderby('count', 'desc')
  561. ->paginate($limit);
  562. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  563. }
  564. /**
  565. * 低价挂网省份统计
  566. * @author 唐远望
  567. * @version 1.0
  568. * @date 2026-02-10
  569. *
  570. */
  571. public function get_low_price_province_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  572. {
  573. $request->scene('get_low_price_province_count')->validate();
  574. $admin_company_id = request('admin_company_id', '0');
  575. $company_id = request('access_token.company_id', '0');
  576. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  577. //终端类型B端、C端、OTO
  578. $terminal_type = request('terminal_type', '');
  579. $product_name = request('product_name', ''); //商品名称
  580. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  581. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  582. $start_time_string = request('start_time', '');
  583. $end_time_string = request('end_time', '');
  584. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  585. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  586. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  587. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  588. // 时间条件
  589. $map = [];
  590. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  591. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  592. // 权限判断
  593. if ($is_admin != 1 && $company_id != 0) {
  594. $map[] = ['company_id', '=', $company_id];
  595. } else {
  596. $map[] = ['company_id', '=', $admin_company_id];
  597. }
  598. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  599. // 禁止挂网省份统计
  600. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  601. if ($terminal_type) {
  602. $platform = [];
  603. switch ($terminal_type) {
  604. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  605. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  606. break;
  607. case '2': //C端:美团、拼多多、天猫、京东、药房网
  608. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  609. break;
  610. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  611. $platform = ['0'];
  612. break;
  613. default:
  614. # code...
  615. break;
  616. }
  617. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  618. }
  619. try {
  620. // 假设 LowPriceGoodsModel 中有 province 字段,表示省份信息
  621. // 查询指定时间范围内的数据,并按 province 分组统计数量
  622. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  623. ->select(['province_name', DB::raw('count(province_name) as count')])
  624. ->groupby('province_name')
  625. ->orderby('count', 'desc')
  626. ->get()->toArray();
  627. $province_totle_count = 0;
  628. if (!empty($result)) {
  629. $province_totle_count = array_sum(array_column($result, 'count'));
  630. foreach ($result as $key => $value) {
  631. $result[$key]['percent'] = round(($value['count'] / $province_totle_count) * 100, 2);
  632. }
  633. }
  634. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  635. } catch (\Exception $e) {
  636. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  637. }
  638. }
  639. /**
  640. * 低价挂网城市统计
  641. * @author 唐远望
  642. * @version 1.0
  643. * @date 2026-02-10
  644. *
  645. */
  646. public function get_low_price_city_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  647. {
  648. $request->scene('get_low_price_city_count')->validate();
  649. $admin_company_id = request('admin_company_id', '0');
  650. $company_id = request('access_token.company_id', '0');
  651. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  652. //终端类型B端、C端、OTO
  653. $province_id = request('province_id', ''); //省份id
  654. $terminal_type = request('terminal_type', '');
  655. $product_name = request('product_name', ''); //商品名称
  656. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  657. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  658. $start_time_string = request('start_time', '');
  659. $end_time_string = request('end_time', '');
  660. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  661. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  662. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  663. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  664. // 时间条件
  665. $map = [];
  666. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  667. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  668. // 权限判断
  669. if ($is_admin != 1 && $company_id != 0) {
  670. $map[] = ['company_id', '=', $company_id];
  671. } else {
  672. $map[] = ['company_id', '=', $admin_company_id];
  673. }
  674. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  675. if ($province_id) $map[] = ['province_id', '=', $province_id];
  676. // 禁止挂网城市统计
  677. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  678. if ($terminal_type) {
  679. $platform = [];
  680. switch ($terminal_type) {
  681. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  682. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  683. break;
  684. case '2': //C端:美团、拼多多、天猫、京东、药房网
  685. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  686. break;
  687. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  688. $platform = ['0'];
  689. break;
  690. default:
  691. # code...
  692. break;
  693. }
  694. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  695. }
  696. try {
  697. // 假设 LowPriceGoodsModel 中有 city 字段,表示城市信息
  698. // 查询指定时间范围内的数据,并按 city 分组统计数量
  699. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  700. ->select(['city_name', DB::raw('count(city_name) as count')])
  701. ->groupby('city_name')
  702. ->orderby('count', 'desc')
  703. ->get()->toArray();
  704. $city_totle_count = 0;
  705. if (!empty($result)) {
  706. $city_totle_count = array_sum(array_column($result, 'count'));
  707. foreach ($result as $key => $value) {
  708. $result[$key]['percent'] = round(($value['count'] / $city_totle_count) * 100, 2);
  709. }
  710. }
  711. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  712. } catch (\Exception $e) {
  713. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  714. }
  715. }
  716. /**
  717. * 低价挂网平台分布
  718. * @author 唐远望
  719. * @version 1.0
  720. * @date 2026-02-27
  721. *
  722. */
  723. public function get_low_price_platform_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  724. {
  725. $request->scene('get_low_price_platform_count')->validate();
  726. $admin_company_id = request('admin_company_id', '0');
  727. $company_id = request('access_token.company_id', '0');
  728. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  729. //终端类型B端、C端、OTO
  730. $terminal_type = request('terminal_type', '');
  731. $product_name = request('product_name', ''); //商品名称
  732. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  733. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  734. $start_time_string = request('start_time', '');
  735. $end_time_string = request('end_time', '');
  736. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  737. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  738. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  739. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  740. // 时间条件
  741. $map = [];
  742. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  743. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  744. // 权限判断
  745. if ($is_admin != 1 && $company_id != 0) {
  746. $map[] = ['company_id', '=', $company_id];
  747. } else {
  748. $map[] = ['company_id', '=', $admin_company_id];
  749. }
  750. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  751. // 禁止挂网平台分布统计
  752. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  753. if ($terminal_type) {
  754. $platform = [];
  755. switch ($terminal_type) {
  756. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  757. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  758. break;
  759. case '2': //C端:美团、拼多多、天猫、京东、药房网
  760. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  761. break;
  762. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  763. $platform = ['0'];
  764. break;
  765. default:
  766. # code...
  767. break;
  768. }
  769. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  770. }
  771. try {
  772. // 假设 LowPriceGoodsModel 中有 platform 字段,表示平台信息
  773. // 查询指定时间范围内的数据,并按 platform 分组统计数量
  774. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  775. ->select(['platform', DB::raw('count(platform) as count')])
  776. ->groupby('platform')
  777. ->orderby('count', 'desc')
  778. ->get()->toArray();
  779. $platform_totle_count = 0;
  780. if (!empty($result)) {
  781. $platform_totle_count = array_sum(array_column($result, 'count'));
  782. foreach ($result as $key => $value) {
  783. $result[$key]['percent'] = round(($value['count'] / $platform_totle_count) * 100, 2);
  784. }
  785. }
  786. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  787. } catch (\Exception $e) {
  788. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  789. }
  790. }
  791. /**
  792. * 低价挂网平台省份分布
  793. * @author 唐远望
  794. * @version 1.0
  795. * @date 2026-02-27
  796. *
  797. */
  798. public function get_low_price_platform_province_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  799. {
  800. $request->scene('get_low_price_platform_province_count')->validate();
  801. $admin_company_id = request('admin_company_id', '0');
  802. $company_id = request('access_token.company_id', '0');
  803. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  804. //终端类型B端、C端、OTO
  805. $terminal_type = request('terminal_type', '');
  806. $product_name = request('product_name', ''); //商品名称
  807. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  808. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  809. $start_time_string = request('start_time', '');
  810. $end_time_string = request('end_time', '');
  811. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  812. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  813. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  814. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  815. // 时间条件
  816. $map = [];
  817. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  818. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  819. // 权限判断
  820. if ($is_admin != 1 && $company_id != 0) {
  821. $map[] = ['company_id', '=', $company_id];
  822. } else {
  823. $map[] = ['company_id', '=', $admin_company_id];
  824. }
  825. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  826. // 禁止挂网平台分布统计
  827. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  828. if ($terminal_type) {
  829. $platform = [];
  830. switch ($terminal_type) {
  831. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  832. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  833. break;
  834. case '2': //C端:美团、拼多多、天猫、京东、药房网
  835. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  836. break;
  837. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  838. $platform = ['0'];
  839. break;
  840. default:
  841. # code...
  842. break;
  843. }
  844. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  845. }
  846. try {
  847. // 假设 LowPriceGoodsModel 中有 province 字段,表示省份信息
  848. // 查询指定时间范围内的数据,并按 province 分组统计数量
  849. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  850. ->select(['province_name', DB::raw('count(province_name) as count')])
  851. ->groupby('province_name')
  852. ->orderby('count', 'desc')
  853. ->get();
  854. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  855. } catch (\Exception $e) {
  856. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  857. }
  858. }
  859. /**
  860. * 禁止挂网平台分布
  861. * @author 唐远望
  862. * @version 1.0
  863. * @date 2026-02-27
  864. *
  865. */
  866. public function get_violation_platform_count(request $request, ViolationProductModel $violationProductModel)
  867. {
  868. $request->scene('get_violation_platform_count')->validate();
  869. $admin_company_id = request('admin_company_id', '0');
  870. $company_id = request('access_token.company_id', '0');
  871. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  872. //终端类型B端、C端、OTO
  873. $terminal_type = request('terminal_type', '');
  874. $product_name = request('product_name', ''); //商品名称
  875. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  876. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  877. $start_time_string = request('start_time', '');
  878. $end_time_string = request('end_time', '');
  879. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  880. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  881. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  882. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  883. // 时间条件
  884. $map = [];
  885. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  886. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  887. // 权限判断
  888. if ($is_admin != 1 && $company_id != 0) {
  889. $map[] = ['company_id', '=', $company_id];
  890. } else {
  891. $map[] = ['company_id', '=', $admin_company_id];
  892. }
  893. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  894. // 禁止挂网平台分布统计
  895. $violationProductModel = $violationProductModel->query();
  896. if ($terminal_type) {
  897. $platform = [];
  898. switch ($terminal_type) {
  899. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  900. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  901. break;
  902. case '2': //C端:美团、拼多多、天猫、京东、药房网
  903. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  904. break;
  905. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  906. $platform = ['0'];
  907. break;
  908. default:
  909. # code...
  910. break;
  911. }
  912. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  913. }
  914. try {
  915. // 假设 ViolationProductModel 中有 platform 字段,表示平台信息
  916. // 查询指定时间范围内的数据,并按 platform 分组统计数量
  917. $result = $violationProductModel->where($map)->where('status', 0)
  918. ->select(['platform', DB::raw('count(platform) as count')])
  919. ->groupby('platform')
  920. ->orderby('count', 'desc')
  921. ->get()->toArray();
  922. $platform_totle_count = 0;
  923. if (!empty($result)) {
  924. $platform_totle_count = array_sum(array_column($result, 'count'));
  925. foreach ($result as $key => $value) {
  926. $result[$key]['percent'] = round(($value['count'] / $platform_totle_count) * 100, 2);
  927. }
  928. }
  929. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  930. } catch (\Exception $e) {
  931. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  932. }
  933. }
  934. /**
  935. * 禁止挂网平台省份分布
  936. * @author 唐远望
  937. * @version 1.0
  938. * @date 2026-02-27
  939. *
  940. */
  941. public function get_violation_platform_province_count(request $request, ViolationProductModel $violationProductModel)
  942. {
  943. $request->scene('get_violation_platform_province_count')->validate();
  944. $admin_company_id = request('admin_company_id', '0');
  945. $company_id = request('access_token.company_id', '0');
  946. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  947. //终端类型B端、C端、OTO
  948. $terminal_type = request('terminal_type', '');
  949. $product_name = request('product_name', ''); //商品名称
  950. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  951. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  952. $start_time_string = request('start_time', '');
  953. $end_time_string = request('end_time', '');
  954. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  955. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  956. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  957. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  958. // 时间条件
  959. $map = [];
  960. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  961. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  962. // 权限判断
  963. if ($is_admin != 1 && $company_id != 0) {
  964. $map[] = ['company_id', '=', $company_id];
  965. } else {
  966. $map[] = ['company_id', '=', $admin_company_id];
  967. }
  968. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  969. // 禁止挂网平台分布统计
  970. $violationProductModel = $violationProductModel->query();
  971. if ($terminal_type) {
  972. $platform = [];
  973. switch ($terminal_type) {
  974. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  975. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  976. break;
  977. case '2': //C端:美团、拼多多、天猫、京东、药房网
  978. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  979. break;
  980. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  981. $platform = ['0'];
  982. break;
  983. default:
  984. # code...
  985. break;
  986. }
  987. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  988. }
  989. try {
  990. // 假设 ViolationProductModel 中有 platform 字段,表示平台信息
  991. // 查询指定时间范围内的数据,并按 platform 分组统计数量
  992. $result = $violationProductModel->where($map)->where('status', 0)
  993. ->select(['province_name', DB::raw('count(province_name) as count')])
  994. ->groupby(['province_name'])
  995. ->orderby('count', 'desc')
  996. ->get();
  997. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  998. } catch (\Exception $e) {
  999. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  1000. }
  1001. }
  1002. /**
  1003. * 违规公司平台占比
  1004. * @author 唐远望
  1005. * @version 1.0
  1006. * @date 2026-03-23
  1007. *
  1008. */
  1009. public function get_violation_company_platform_proportion(request $request, ViolationProductModel $violationProductModel)
  1010. {
  1011. $request->scene('get_violation_company_platform_proportion')->validate();
  1012. $admin_company_id = request('admin_company_id', '0');
  1013. $company_id = request('access_token.company_id', '0');
  1014. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  1015. //终端类型B端、C端、OTO
  1016. $terminal_type = request('terminal_type', '');
  1017. $product_name = request('product_name', ''); //商品名称
  1018. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  1019. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  1020. $start_time_string = request('start_time', '');
  1021. $end_time_string = request('end_time', '');
  1022. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  1023. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  1024. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  1025. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  1026. // 时间条件
  1027. $map = [];
  1028. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  1029. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  1030. // 权限判断
  1031. if ($is_admin != 1 && $company_id != 0) {
  1032. $map[] = ['company_id', '=', $company_id];
  1033. } else {
  1034. $map[] = ['company_id', '=', $admin_company_id];
  1035. }
  1036. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  1037. // 禁止挂网平台分布统计
  1038. $violationProductModel = $violationProductModel->query();
  1039. if ($terminal_type) {
  1040. $platform = [];
  1041. switch ($terminal_type) {
  1042. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  1043. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1044. break;
  1045. case '2': //C端:美团、拼多多、天猫、京东、药房网
  1046. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1047. break;
  1048. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  1049. $platform = ['0'];
  1050. break;
  1051. default:
  1052. # code...
  1053. break;
  1054. }
  1055. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  1056. }
  1057. try {
  1058. // 假设 LowPriceGoodsModel 中有 platform 字段,表示平台信息
  1059. // 查询指定时间范围内的数据,并按 platform 分组统计数量
  1060. $result = $violationProductModel->where($map)->where('status', 0)
  1061. ->select(['platform', DB::raw('count(platform) as count')])
  1062. ->distinct('company_name')
  1063. ->groupby('platform')
  1064. ->orderby('count', 'desc')
  1065. ->get()->toArray();
  1066. $platform_totle_count = 0;
  1067. if (!empty($result)) {
  1068. $platform_totle_count = array_sum(array_column($result, 'count'));
  1069. foreach ($result as $key => $value) {
  1070. $result[$key]['percent'] = round(($value['count'] / $platform_totle_count) * 100, 2);
  1071. }
  1072. }
  1073. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  1074. } catch (\Exception $e) {
  1075. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  1076. }
  1077. }
  1078. /**
  1079. * 违规店铺平台占比
  1080. * @author 唐远望
  1081. * @version 1.0
  1082. * @date 2026-03-23
  1083. *
  1084. */
  1085. public function get_violation_store_platform_proportion(request $request, ViolationStoreModel $ViolationStoreModel)
  1086. {
  1087. $request->scene('get_violation_store_platform_proportion')->validate();
  1088. $admin_company_id = request('admin_company_id', '0');
  1089. $company_id = request('access_token.company_id', '0');
  1090. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  1091. //终端类型B端、C端、OTO
  1092. $terminal_type = request('terminal_type', '');
  1093. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  1094. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  1095. $start_time_string = request('start_time', '');
  1096. $end_time_string = request('end_time', '');
  1097. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  1098. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  1099. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  1100. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  1101. // 时间条件
  1102. $map = [];
  1103. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  1104. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  1105. // 权限判断
  1106. if ($is_admin != 1 && $company_id != 0) {
  1107. $map[] = ['company_id', '=', $company_id];
  1108. } else {
  1109. $map[] = ['company_id', '=', $admin_company_id];
  1110. }
  1111. // 禁止挂网平台分布统计
  1112. $ViolationStoreModel = $ViolationStoreModel->query();
  1113. if ($terminal_type) {
  1114. $platform = [];
  1115. switch ($terminal_type) {
  1116. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  1117. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1118. break;
  1119. case '2': //C端:美团、拼多多、天猫、京东、药房网
  1120. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1121. break;
  1122. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  1123. $platform = ['0'];
  1124. break;
  1125. default:
  1126. # code...
  1127. break;
  1128. }
  1129. $ViolationStoreModel = $ViolationStoreModel->whereIn('platform', $platform);
  1130. }
  1131. try {
  1132. // 假设 LowPriceGoodsModel 中有 platform 字段,表示平台信息
  1133. // 查询指定时间范围内的数据,并按 platform 分组统计数量
  1134. $result = $ViolationStoreModel->where($map)->where('status', 0)
  1135. ->select(['platform', DB::raw('count(platform) as count')])
  1136. ->groupby('platform')
  1137. ->orderby('count', 'desc')
  1138. ->get()->toArray();
  1139. $platform_totle_count = 0;
  1140. if (!empty($result)) {
  1141. $platform_totle_count = array_sum(array_column($result, 'count'));
  1142. foreach ($result as $key => $value) {
  1143. $result[$key]['percent'] = round(($value['count'] / $platform_totle_count) * 100, 2);
  1144. }
  1145. }
  1146. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  1147. } catch (\Exception $e) {
  1148. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  1149. }
  1150. }
  1151. /**
  1152. * 违规店铺平台省份分布
  1153. * @author 唐远望
  1154. * @version 1.0
  1155. * @date 2026-03-23
  1156. *
  1157. */
  1158. public function get_violation_store_province_count(request $request, ViolationStoreModel $ViolationStoreModel)
  1159. {
  1160. $request->scene('get_violation_store_province_count')->validate();
  1161. $admin_company_id = request('admin_company_id', '0');
  1162. $company_id = request('access_token.company_id', '0');
  1163. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  1164. //终端类型B端、C端、OTO
  1165. $terminal_type = request('terminal_type', '');
  1166. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  1167. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  1168. $start_time_string = request('start_time', '');
  1169. $end_time_string = request('end_time', '');
  1170. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  1171. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  1172. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  1173. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  1174. // 时间条件
  1175. $map = [];
  1176. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  1177. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  1178. // 权限判断
  1179. if ($is_admin != 1 && $company_id != 0) {
  1180. $map[] = ['company_id', '=', $company_id];
  1181. } else {
  1182. $map[] = ['company_id', '=', $admin_company_id];
  1183. }
  1184. // 违规公司平台分布统计
  1185. $ViolationStoreModel = $ViolationStoreModel->query();
  1186. if ($terminal_type) {
  1187. $platform = [];
  1188. switch ($terminal_type) {
  1189. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  1190. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1191. break;
  1192. case '2': //C端:美团、拼多多、天猫、京东、药房网
  1193. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1194. break;
  1195. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  1196. $platform = ['0'];
  1197. break;
  1198. default:
  1199. # code...
  1200. break;
  1201. }
  1202. $ViolationStoreModel = $ViolationStoreModel->whereIn('platform', $platform);
  1203. }
  1204. try {
  1205. // 假设 $violationProductModel 中有 province 字段,表示省份信息
  1206. // 查询指定时间范围内的数据,并按 province 分组统计数量
  1207. $result = $ViolationStoreModel->where($map)->where('status', 0)
  1208. ->select(['province_name', DB::raw('count(province_name) as count')])
  1209. ->groupby('province_name')
  1210. ->orderby('count', 'desc')
  1211. ->get();
  1212. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  1213. } catch (\Exception $e) {
  1214. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  1215. }
  1216. }
  1217. /**
  1218. * 违规店铺省份统计占比
  1219. * @author 唐远望
  1220. * @version 1.0
  1221. * @date 2026-03-23
  1222. *
  1223. */
  1224. public function get_violation_store_province_proportion(request $request, ViolationStoreModel $ViolationStoreModel)
  1225. {
  1226. $request->scene('get_violation_store_province_proportion')->validate();
  1227. $admin_company_id = request('admin_company_id', '0');
  1228. $company_id = request('access_token.company_id', '0');
  1229. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  1230. //终端类型B端、C端、OTO
  1231. $terminal_type = request('terminal_type', '');
  1232. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  1233. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  1234. $start_time_string = request('start_time', '');
  1235. $end_time_string = request('end_time', '');
  1236. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  1237. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  1238. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  1239. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  1240. // 时间条件
  1241. $map = [];
  1242. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  1243. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  1244. // 权限判断
  1245. if ($is_admin != 1 && $company_id != 0) {
  1246. $map[] = ['company_id', '=', $company_id];
  1247. } else {
  1248. $map[] = ['company_id', '=', $admin_company_id];
  1249. }
  1250. // 违规店铺省份统计
  1251. $ViolationStoreModel = $ViolationStoreModel->query();
  1252. if ($terminal_type) {
  1253. $platform = [];
  1254. switch ($terminal_type) {
  1255. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  1256. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1257. break;
  1258. case '2': //C端:美团、拼多多、天猫、京东、药房网
  1259. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1260. break;
  1261. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  1262. $platform = ['0'];
  1263. break;
  1264. default:
  1265. # code...
  1266. break;
  1267. }
  1268. $ViolationStoreModel = $ViolationStoreModel->whereIn('platform', $platform);
  1269. }
  1270. try {
  1271. // 假设 $ViolationStoreModel 中有 province 字段,表示省份信息
  1272. // 查询指定时间范围内的数据,并按 province 分组统计数量
  1273. $result = $ViolationStoreModel->where($map)->where('status', 0)
  1274. ->select(['province_name', DB::raw('count(province_name) as count')])
  1275. ->groupby('province_name')
  1276. ->orderby('count', 'desc')
  1277. ->get()->toArray();
  1278. $province_totle_count = 0;
  1279. if (!empty($result)) {
  1280. $province_totle_count = array_sum(array_column($result, 'count'));
  1281. //计算占比
  1282. foreach ($result as $key => $value) {
  1283. $result[$key]['percent'] = round(($value['count'] / $province_totle_count) * 100, 2);
  1284. }
  1285. }
  1286. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  1287. } catch (\Exception $e) {
  1288. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  1289. }
  1290. }
  1291. /**
  1292. * 违规店铺城市统计占比
  1293. * @author 唐远望
  1294. * @version 1.0
  1295. * @date 2026-03-23
  1296. *
  1297. */
  1298. public function get_violation_store_city_proportion(request $request, ViolationStoreModel $ViolationStoreModel)
  1299. {
  1300. $request->scene('get_violation_store_city_proportion')->validate();
  1301. $admin_company_id = request('admin_company_id', '0');
  1302. $company_id = request('access_token.company_id', '0');
  1303. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  1304. //终端类型B端、C端、OTO
  1305. $province_id = request('province_id', ''); //省份id
  1306. $terminal_type = request('terminal_type', '');
  1307. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  1308. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  1309. $start_time_string = request('start_time', '');
  1310. $end_time_string = request('end_time', '');
  1311. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  1312. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  1313. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  1314. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  1315. // 时间条件
  1316. $map = [];
  1317. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  1318. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  1319. if ($province_id) $map[] = ['province_id', '=', $province_id];
  1320. // 权限判断
  1321. if ($is_admin != 1 && $company_id != 0) {
  1322. $map[] = ['company_id', '=', $company_id];
  1323. } else {
  1324. $map[] = ['company_id', '=', $admin_company_id];
  1325. }
  1326. // 违规店铺省份统计
  1327. $ViolationStoreModel = $ViolationStoreModel->query();
  1328. if ($terminal_type) {
  1329. $platform = [];
  1330. switch ($terminal_type) {
  1331. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  1332. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1333. break;
  1334. case '2': //C端:美团、拼多多、天猫、京东、药房网
  1335. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1336. break;
  1337. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  1338. $platform = ['0'];
  1339. break;
  1340. default:
  1341. # code...
  1342. break;
  1343. }
  1344. $ViolationStoreModel = $ViolationStoreModel->whereIn('platform', $platform);
  1345. }
  1346. try {
  1347. // 假设 $ViolationStoreModel 中有 province 字段,表示省份信息
  1348. // 查询指定时间范围内的数据,并按 province 分组统计数量
  1349. $result = $ViolationStoreModel->where($map)->where('status', 0)
  1350. ->select(['city_name', DB::raw('count(city_name) as count')])
  1351. ->distinct('company_name')
  1352. ->groupby('city_name')
  1353. ->orderby('count', 'desc')
  1354. ->get()->toArray();
  1355. $province_totle_count = 0;
  1356. if (!empty($result)) {
  1357. $province_totle_count = array_sum(array_column($result, 'count'));
  1358. //计算占比
  1359. foreach ($result as $key => $value) {
  1360. $result[$key]['percent'] = round(($value['count'] / $province_totle_count) * 100, 2);
  1361. }
  1362. }
  1363. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  1364. } catch (\Exception $e) {
  1365. return json_send(['code' => 'error', 'msg' => '获取失败:' . $e->getMessage()]);
  1366. }
  1367. }
  1368. /*
  1369. * 低价挂网商品规格数统计排行
  1370. * @author 唐远望
  1371. * @version 1.0
  1372. * @date 2026-03-24
  1373. *
  1374. */
  1375. public function get_low_price_product_spec_count(request $request, LowPriceGoodsModel $LowPriceGoodsModel)
  1376. {
  1377. $request->scene('get_low_price_product_spec_count')->validate();
  1378. $admin_company_id = request('admin_company_id', '0');
  1379. $company_id = request('access_token.company_id', '0');
  1380. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  1381. //终端类型B端、C端、OTO
  1382. $terminal_type = request('terminal_type', '');
  1383. $limit = request('limit', config('page_num', 10));
  1384. $product_name = request('product_name', ''); //商品名称
  1385. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  1386. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  1387. $start_time_string = request('start_time', '');
  1388. $end_time_string = request('end_time', '');
  1389. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  1390. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  1391. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  1392. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  1393. // 时间条件
  1394. $map = [];
  1395. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  1396. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  1397. // 权限判断
  1398. if ($is_admin != 1 && $company_id != 0) {
  1399. $map[] = ['company_id', '=', $company_id];
  1400. } else {
  1401. $map[] = ['company_id', '=', $admin_company_id];
  1402. }
  1403. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  1404. $LowPriceGoodsModel = $LowPriceGoodsModel->query();
  1405. if ($terminal_type) {
  1406. $platform = [];
  1407. switch ($terminal_type) {
  1408. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  1409. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1410. break;
  1411. case '2': //C端:美团、拼多多、天猫、京东、药房网
  1412. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1413. break;
  1414. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  1415. $platform = ['0'];
  1416. break;
  1417. default:
  1418. # code...
  1419. break;
  1420. }
  1421. $LowPriceGoodsModel = $LowPriceGoodsModel->whereIn('platform', $platform);
  1422. }
  1423. $result = $LowPriceGoodsModel->where($map)->where('status', 0)
  1424. ->select(['product_name', 'product_specs', DB::raw('count(*) as count')])
  1425. ->groupby('product_name', 'product_specs')
  1426. ->orderby('count', 'desc')
  1427. ->paginate($limit);
  1428. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  1429. }
  1430. /**
  1431. * 禁止挂网商品规格数统计排行
  1432. * @author 唐远望
  1433. * @version 1.0
  1434. * @date 2026-03-24
  1435. *
  1436. */
  1437. public function get_violation_product_spec_count(request $request, ViolationProductModel $violationProductModel)
  1438. {
  1439. $request->scene('get_violation_product_spec_count')->validate();
  1440. $admin_company_id = request('admin_company_id', '0');
  1441. $company_id = request('access_token.company_id', '0');
  1442. //终端类型B端、C端、OTO
  1443. $terminal_type = request('terminal_type', '');
  1444. $product_name = request('product_name', ''); //商品名称
  1445. $is_admin = request('access_token.is_admin', '0'); //是否管理员操作 0=是1=否
  1446. $limit = request('limit', config('page_num', 10));
  1447. $yesterdayStart = Carbon::yesterday()->startOfDay()->getTimestamp(); // 昨天开始时间 00:00:00
  1448. $yesterdayEnd = Carbon::yesterday()->endOfDay()->getTimestamp(); // 昨天结束时间 23:59:59
  1449. $start_time_string = request('start_time', '');
  1450. $end_time_string = request('end_time', '');
  1451. $start_time = $start_time_string ? strtotime($start_time_string . ' 00:00:00') : $yesterdayStart;
  1452. $end_time = $end_time_string ? strtotime($end_time_string . ' 23:59:59') : $yesterdayEnd;
  1453. $todayStart = Carbon::today()->startOfDay()->getTimestamp(); // 今天开始时间 00:00:00
  1454. // if ($start_time > $todayStart || $end_time > $todayStart) return json_send(['code' => 'error', 'msg' => '不支持查询今天或以后时间', 'data' => '']);
  1455. // 时间条件
  1456. $map = [];
  1457. if ($start_time) $map[] = ['insert_time', '>=', $start_time];
  1458. if ($end_time) $map[] = ['insert_time', '<=', $end_time];
  1459. // 权限判断
  1460. if ($is_admin != 1 && $company_id != 0) {
  1461. $map[] = ['company_id', '=', $company_id];
  1462. } else {
  1463. $map[] = ['company_id', '=', $admin_company_id];
  1464. }
  1465. if ($product_name) $map[] = ['product_name', 'like', '%' . $product_name . '%'];
  1466. $violationProductModel = $violationProductModel->query();
  1467. if ($terminal_type) {
  1468. $platform = [];
  1469. switch ($terminal_type) {
  1470. case '1': //B端:药师帮、1药城、药久久、药易购、药帮忙、熊猫药药
  1471. $platform = ['0', '5', '6', '7', '8', '9', '10']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1472. break;
  1473. case '2': //C端:美团、拼多多、天猫、京东、药房网
  1474. $platform = ['0', '1', '2', '3', '4','11']; //1=淘宝,2=京东,3=拼多多,4=美团,5=药师帮,6=1药城,7=药久久,8=药易购,9=药帮忙,10=熊猫药药11=药房网
  1475. break;
  1476. case '3': //OTO:美团买药、淘宝闪送、京东秒送
  1477. $platform = ['0'];
  1478. break;
  1479. default:
  1480. # code...
  1481. break;
  1482. }
  1483. $violationProductModel = $violationProductModel->whereIn('platform', $platform);
  1484. }
  1485. $result = $violationProductModel->where($map)->where('status', 0)
  1486. ->select(['product_name', 'product_specs', DB::raw('count(*) as count')])
  1487. ->groupby('product_name', 'product_specs')
  1488. ->orderby('count', 'desc')
  1489. ->paginate($limit);
  1490. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  1491. }
  1492. }