BasicPanel.php 92 KB

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