OrderController.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. <?php
  2. namespace App\Http\Controllers\App;
  3. use App\Filters\BikeFilter;
  4. use App\Filters\CardRidingOrderFilter;
  5. use App\Filters\DepositCardOrderFilter;
  6. use App\Filters\DepositFilter;
  7. use App\Filters\DepositOrderFilter;
  8. use App\Filters\OrderFilter;
  9. use App\Filters\OrderRentFilter;
  10. use App\Filters\RechargeOrderFilter;
  11. use App\Filters\UserFilter;
  12. use App\Filters\WalletLogFilter;
  13. use App\Http\Resources\App\OrderResource;
  14. use App\Models\AdminMerchant;
  15. use App\Models\AdminUser;
  16. use App\Models\AdminUserArea;
  17. use App\Models\Bike;
  18. use App\Models\CardRidingOrder;
  19. use App\Models\DepositCardOrder;
  20. use App\Models\DepositOrder;
  21. use App\Models\DepositRefund;
  22. use App\Models\LocationsLog;
  23. use App\Models\Order;
  24. use App\Models\OrderRent;
  25. use App\Models\RechargeOrder;
  26. use App\Models\User;
  27. use App\Models\WalletLog;
  28. use App\Utils\Admin;
  29. use Carbon\Carbon;
  30. use Illuminate\Http\Request;
  31. use App\Http\Controllers\Controller;
  32. use Illuminate\Support\Facades\Cache;
  33. use Illuminate\Support\Facades\DB;
  34. use Illuminate\Support\Facades\Log;
  35. class OrderController extends AppBaseController
  36. {
  37. /**
  38. * orderList 订单列表
  39. *
  40. * @param OrderFilter $filter
  41. * @return \Illuminate\Http\JsonResponse
  42. * @author Fx
  43. *
  44. */
  45. public function orderList(OrderFilter $filter)
  46. {
  47. $area_ids = self::$areaIds;
  48. $order = Order::query()
  49. ->whereIn('area_id', $area_ids)
  50. ->where(AdminMerchant::getMerchantWhere())
  51. ->filter($filter)
  52. ->with('users')
  53. ->where('status', '!=', Order::STATUS_CLOSE_ORDER)
  54. ->orderByDesc('id')
  55. ->paginate();
  56. return $this->ok(OrderResource::collection($order));
  57. }
  58. /**
  59. * orderStatistics 订单统计
  60. *
  61. * @param OrderFilter $filter
  62. * @return \Illuminate\Http\JsonResponse
  63. * @author Fx
  64. *
  65. */
  66. public function orderStatistics(OrderFilter $filter)
  67. {
  68. $area_ids = self::$areaIds;
  69. // 总订单数
  70. $order_total = Order::query()
  71. ->where(AdminMerchant::getMerchantWhere())
  72. ->whereIn('area_id', $area_ids)
  73. ->filter($filter)
  74. ->where('status', Order::STATUS_COMPLETE_ORDER)
  75. ->count('id');
  76. $order_rent_total = OrderRent::query()
  77. ->where(AdminMerchant::getMerchantWhere())
  78. ->whereIn('area_id', $area_ids)
  79. ->filter($filter)
  80. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  81. ->count('id');
  82. $order_total += $order_rent_total;
  83. // 今日新增订单数
  84. $today_add_order = Order::query()
  85. ->where(AdminMerchant::getMerchantWhere())
  86. ->whereIn('area_id', $area_ids)
  87. ->filter($filter)
  88. ->where('created_at', '>', Carbon::today())
  89. ->where('status', Order::STATUS_COMPLETE_ORDER)
  90. ->count('id');
  91. $today_add_order_rent = OrderRent::query()
  92. ->where(AdminMerchant::getMerchantWhere())
  93. ->whereIn('area_id', $area_ids)
  94. ->filter($filter)
  95. ->where('pay_time', '>', Carbon::today())
  96. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  97. ->count('id');
  98. $today_add_order += $today_add_order_rent;
  99. // 骑行中订单数
  100. $riding_status = [
  101. Order::STATUS_RIDE_BIKE,
  102. // Order::STATUS_CLOSE_BIKE, // 待支付
  103. Order::STATUS_PAUSE_BIKE,
  104. ];
  105. $riding_order = Order::query()
  106. ->where(AdminMerchant::getMerchantWhere())
  107. ->whereIn('area_id', $area_ids)
  108. ->filter($filter)
  109. ->whereIn('status', $riding_status)
  110. ->count('id');
  111. $riding_order_rent = OrderRent::query()
  112. ->where(AdminMerchant::getMerchantWhere())
  113. ->whereIn('area_id', $area_ids)
  114. ->filter($filter)
  115. ->where('status', OrderRent::STATUS_RENT_BIKE)
  116. ->count('id');
  117. $riding_order += $riding_order_rent;
  118. // 待支付
  119. $waiting_pay_order = Order::query()
  120. ->where(AdminMerchant::getMerchantWhere())
  121. ->whereIn('area_id', $area_ids)
  122. ->filter($filter)
  123. ->where('status', Order::STATUS_CLOSE_BIKE)
  124. ->count('id');
  125. $waiting_pay_rent = OrderRent::query()
  126. ->where(AdminMerchant::getMerchantWhere())
  127. ->whereIn('area_id', $area_ids)
  128. ->filter($filter)
  129. ->where('status', OrderRent::STATUS_CLOSE_RENT_BIKE)
  130. ->count('id');
  131. $waiting_pay_order += $waiting_pay_rent;
  132. // 今日新增收入
  133. $today_add_money = Order::query()
  134. ->where(AdminMerchant::getMerchantWhere())
  135. ->whereIn('area_id', $area_ids)
  136. ->filter($filter)
  137. ->where('pay_time', '>', Carbon::today())
  138. ->where('status', Order::STATUS_COMPLETE_ORDER)
  139. ->sum('pay_money');
  140. $today_add_money_rent = OrderRent::query()
  141. ->where(AdminMerchant::getMerchantWhere())
  142. ->whereIn('area_id', $area_ids)
  143. ->filter($filter)
  144. ->where('pay_time', '>', Carbon::today())
  145. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  146. ->sum('pay_money');
  147. $today_add_money += $today_add_money_rent;
  148. $order = [
  149. 'order_total' => $order_total ?? 0,
  150. 'today_add_order' => $today_add_order ?? 0,
  151. 'riding_order' => $riding_order ?? 0,
  152. 'today_add_money' => $today_add_money ?? 0,
  153. 'waiting_pay' => $waiting_pay_order ?? 0,
  154. ];
  155. return $this->ok($order);
  156. }
  157. /**
  158. * orderProfitStatistics 订单收益统计
  159. *
  160. * @param WalletLogFilter $walletLogFilter
  161. * @param DepositFilter $depositFilter
  162. * @param OrderFilter $orderFilter
  163. * @param OrderRentFilter $orderRentFilter
  164. * @return \Illuminate\Http\JsonResponse
  165. * @author Fx
  166. *
  167. */
  168. public function orderProfitStatistics(WalletLogFilter $walletLogFilter, DepositFilter $depositFilter, OrderFilter $orderFilter, OrderRentFilter $orderRentFilter)
  169. {
  170. $area_ids = self::$areaIds;
  171. $admin_type = Admin::user()->type;
  172. if ($admin_type == AdminUser::TYPE_WORKER) {
  173. $data = [
  174. 'totalProfit' => $totalProfit ?? 0,
  175. 'depositTotal' => $depositTotal ?? 0,
  176. 'todayProfit' => $todayProfit ?? 0,
  177. 'depositToday' => $depositToday ?? 0,
  178. 'monthProfit' => $monthProfit ?? 0,
  179. ];
  180. return $this->ok($data);
  181. }
  182. // 总收益
  183. // $totalProfit = WalletLog::query()
  184. // ->whereIn('area_id', $area_ids)
  185. // ->filter($walletLogFilter)
  186. // ->whereIn('type', WalletLog::$subType)
  187. // ->sum('money');
  188. $totalOrderProfit = Order::query()
  189. ->where(AdminMerchant::getMerchantWhere())
  190. ->whereIn('area_id', $area_ids)
  191. ->filter($orderFilter)
  192. ->where('status', Order::STATUS_COMPLETE_ORDER)
  193. ->sum('pay_money');
  194. $totalOrderRentProfit = OrderRent::query()
  195. ->where(AdminMerchant::getMerchantWhere())
  196. ->whereIn('area_id', $area_ids)
  197. ->filter($orderRentFilter)
  198. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  199. ->sum('pay_money');
  200. $totalProfit = bcadd($totalOrderProfit, $totalOrderRentProfit, 0);
  201. // 总押金
  202. $depositTotal = DepositOrder::query()
  203. ->where(AdminMerchant::getMerchantWhere())
  204. ->where('pay_status', DepositOrder::PAY_STATUS_OK)
  205. ->where('is_refund', DepositOrder::REFUND_NO)
  206. ->whereIn('area_id', $area_ids)
  207. ->filter($depositFilter)
  208. ->sum('pay_money');
  209. // 今日收益
  210. // $todayProfit = WalletLog::query()
  211. // ->whereIn('area_id', $area_ids)
  212. // ->filter($walletLogFilter)
  213. // ->whereIn('type', WalletLog::$subType)
  214. // ->where('created_at', '>', Carbon::today())
  215. // ->sum('money');
  216. $todayOrderProfit = Order::query()
  217. ->where(AdminMerchant::getMerchantWhere())
  218. ->whereIn('area_id', $area_ids)
  219. ->filter($orderFilter)
  220. ->where('status', Order::STATUS_COMPLETE_ORDER)
  221. ->where('created_at', '>', Carbon::today())
  222. ->sum('pay_money');
  223. $todayOrderRentProfit = OrderRent::query()
  224. ->where(AdminMerchant::getMerchantWhere())
  225. ->whereIn('area_id', $area_ids)
  226. ->filter($orderRentFilter)
  227. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  228. ->where('created_at', '>', Carbon::today())
  229. ->sum('pay_money');
  230. $todayProfit = bcadd($todayOrderProfit, $todayOrderRentProfit, 0);
  231. // 今日新增押金
  232. $depositToday = DepositOrder::query()
  233. ->where(AdminMerchant::getMerchantWhere())
  234. ->where('pay_status', DepositOrder::PAY_STATUS_OK)
  235. ->where('is_refund', DepositOrder::REFUND_NO)
  236. ->whereIn('area_id', $area_ids)
  237. ->filter($depositFilter)
  238. ->where('created_at', '>', Carbon::today())
  239. ->sum('pay_money');
  240. // 本月收益
  241. // $monthProfit = WalletLog::query()
  242. // ->whereIn('area_id', $area_ids)
  243. // ->filter($walletLogFilter)
  244. // ->whereIn('type', WalletLog::$subType)
  245. // ->where('created_at', '>', Carbon::today()->format('Y-m-01 00:00:00'))
  246. // ->sum('money');
  247. $monthOrderProfit = Order::query()
  248. ->where(AdminMerchant::getMerchantWhere())
  249. ->whereIn('area_id', $area_ids)
  250. ->filter($orderFilter)
  251. ->where('status', Order::STATUS_COMPLETE_ORDER)
  252. ->where('created_at', '>', Carbon::today()->format('Y-m-01 00:00:00'))
  253. ->sum('pay_money');
  254. $monthOrderRentProfit = OrderRent::query()
  255. ->where(AdminMerchant::getMerchantWhere())
  256. ->whereIn('area_id', $area_ids)
  257. ->filter($orderRentFilter)
  258. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  259. ->where('created_at', '>', Carbon::today()->format('Y-m-01 00:00:00'))
  260. ->sum('pay_money');
  261. $monthProfit = bcadd($monthOrderProfit, $monthOrderRentProfit, 0);
  262. $data = [
  263. 'totalProfit' => floor(abs($totalProfit)) ?? 0,
  264. 'depositTotal' => floor($depositTotal) ?? 0,
  265. 'todayProfit' => floor($todayProfit) ?? 0,
  266. 'depositToday' => floor($depositToday) ?? 0,
  267. 'monthProfit' => floor($monthProfit) ?? 0,
  268. ];
  269. return $this->ok($data);
  270. }
  271. /**
  272. * profitDetail 收益详情
  273. *
  274. * @param Request $request
  275. * @param OrderFilter $orderFilter
  276. * @param OrderRentFilter $orderRentFilter
  277. * @param DepositFilter $depositFilter
  278. * @param WalletLogFilter $walletLogFilter
  279. * @param UserFilter $userFilter
  280. * @return \Illuminate\Http\JsonResponse
  281. * @author Fx
  282. *
  283. */
  284. public function profitDetail(Request $request, OrderFilter $orderFilter, OrderRentFilter $orderRentFilter, DepositFilter $depositFilter, WalletLogFilter $walletLogFilter, UserFilter $userFilter,BikeFilter $bikeFilter,RechargeOrderFilter $rechargeOrderFilter,CardRidingOrderFilter $cardRidingOrderFilter,DepositCardOrderFilter $depositCardOrderFilter)
  285. {
  286. $area_ids = self::$areaIds;
  287. $time_between = $request->get('pay_time_between') ?? [];
  288. if (empty($time_between)) return $this->error('参数错误');
  289. $t1 = Carbon::make($time_between[0]);
  290. $t2 = Carbon::make($time_between[1]);
  291. $days = $t1->diffInDays($t2);
  292. // 总收益
  293. $totalProfit = WalletLog::query()
  294. ->where(AdminMerchant::getMerchantWhere())
  295. ->filter($walletLogFilter)
  296. ->whereIn('area_id', $area_ids)
  297. ->where('created_at', '>', date('Y-m-d H:i:s', strtotime($time_between[0])))
  298. ->where('created_at', '<', date('Y-m-d H:i:s', strtotime($time_between[1])))
  299. ->whereIn('type', WalletLog::$subType)
  300. ->sum('money');
  301. // 总押金
  302. $depositTotal = DepositOrder::query()
  303. ->where(AdminMerchant::getMerchantWhere())
  304. ->where('pay_status', DepositOrder::PAY_STATUS_OK)
  305. ->where('is_refund', DepositOrder::REFUND_NO)
  306. ->whereIn('area_id', $area_ids)
  307. ->filter($depositFilter)
  308. ->sum('pay_money');
  309. // 普通订单
  310. $orderTotalProfit = Order::query()
  311. ->where(AdminMerchant::getMerchantWhere())
  312. ->where('pay_status', Order::PAY_STATUS_OK)
  313. ->where('status', Order::STATUS_COMPLETE_ORDER)
  314. ->whereIn('area_id', $area_ids)
  315. ->filter($orderFilter)
  316. ->sum('pay_money');
  317. // 骑行花费
  318. $orderTotalTimeProfit = Order::query()
  319. ->where(AdminMerchant::getMerchantWhere())
  320. ->where('pay_status', Order::PAY_STATUS_OK)
  321. ->where('status', Order::STATUS_COMPLETE_ORDER)
  322. ->whereIn('area_id', $area_ids)
  323. ->filter($orderFilter)
  324. ->sum('time_money');
  325. $orderTotal = Order::query()
  326. ->where(AdminMerchant::getMerchantWhere())
  327. ->where('pay_status', Order::PAY_STATUS_OK)
  328. ->where('status', Order::STATUS_COMPLETE_ORDER)
  329. ->whereIn('area_id', $area_ids)
  330. ->filter($orderFilter)
  331. ->count();
  332. $orderDispatchTotalProfit = Order::query()
  333. ->where(AdminMerchant::getMerchantWhere())
  334. ->where('pay_status', Order::PAY_STATUS_OK)
  335. ->where('status', Order::STATUS_COMPLETE_ORDER)
  336. ->whereIn('area_id', $area_ids)
  337. ->filter($orderFilter)
  338. ->sum('dispatch_money');
  339. // 日租订单
  340. $orderRentTotalProfit = OrderRent::query()
  341. ->where(AdminMerchant::getMerchantWhere())
  342. ->where('pay_status', OrderRent::PAY_STATUS_OK)
  343. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  344. ->whereIn('area_id', $area_ids)
  345. ->filter($orderRentFilter)
  346. ->sum('pay_money');
  347. // 日租超时花费
  348. $orderRentTotalTimeProfit = OrderRent::query()
  349. ->where(AdminMerchant::getMerchantWhere())
  350. ->where('pay_status', OrderRent::PAY_STATUS_OK)
  351. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  352. ->whereIn('area_id', $area_ids)
  353. ->filter($orderRentFilter)
  354. ->sum('time_money');
  355. // 日租租金
  356. $orderRentTotalRentProfit = OrderRent::query()
  357. ->where(AdminMerchant::getMerchantWhere())
  358. ->where('pay_status', OrderRent::PAY_STATUS_OK)
  359. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  360. ->whereIn('area_id', $area_ids)
  361. ->filter($orderRentFilter)
  362. ->sum('rent_money');
  363. $orderRentTotal = OrderRent::query()
  364. ->where(AdminMerchant::getMerchantWhere())
  365. ->where('pay_status', OrderRent::PAY_STATUS_OK)
  366. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  367. ->whereIn('area_id', $area_ids)
  368. ->filter($orderRentFilter)
  369. ->count();
  370. // 日租调度费
  371. $orderRentDispatchTotalProfit = OrderRent::query()
  372. ->where(AdminMerchant::getMerchantWhere())
  373. ->where('pay_status', OrderRent::PAY_STATUS_OK)
  374. ->where('status', OrderRent::STATUS_COMPLETE_ORDER)
  375. ->whereIn('area_id', $area_ids)
  376. ->filter($orderRentFilter)
  377. ->sum('dispatch_money');
  378. // 已实名用户数
  379. $userTotalCardOk = User::query()
  380. ->where(AdminMerchant::getMerchantWhere())
  381. ->filter($userFilter)
  382. ->whereIn('register_area_id', $area_ids)
  383. ->where('is_card_certified', User::CARD_OK)
  384. ->where('created_at', '>', date('Y-m-d H:i:s', strtotime($time_between[0])))
  385. ->where('created_at', '<', date('Y-m-d H:i:s', strtotime($time_between[1])))
  386. ->count();
  387. // 已缴纳押金用户数
  388. $userDepositTotal = User::query()
  389. ->where(AdminMerchant::getMerchantWhere())
  390. ->filter($userFilter)
  391. ->whereIn('register_area_id', $area_ids)
  392. ->where('is_card_certified', User::CARD_OK)
  393. ->where('is_card_certified', User::CARD_OK)
  394. ->where('is_deposit', User::DEPOSIT_OK)
  395. ->count();
  396. $orderWaitPay = Order::query()
  397. ->where(AdminMerchant::getMerchantWhere())
  398. ->filter($orderFilter)
  399. ->where('status', Order::STATUS_CLOSE_BIKE)
  400. ->whereIn('area_id', $area_ids)
  401. ->sum('pay_money');
  402. $orderRentWaitPay = OrderRent::query()
  403. ->where(AdminMerchant::getMerchantWhere())
  404. ->filter($orderRentFilter)
  405. ->where('status', OrderRent::STATUS_CLOSE_RENT_BIKE)
  406. ->whereIn('area_id', $area_ids)
  407. ->sum('pay_money');
  408. // 待支付
  409. $wiatPayTotal = bcadd($orderWaitPay, $orderRentWaitPay, 2);
  410. $orderWaitPayNum = Order::query()
  411. ->where(AdminMerchant::getMerchantWhere())
  412. ->filter($orderFilter)
  413. ->where('status', Order::STATUS_CLOSE_BIKE)
  414. ->whereIn('area_id', $area_ids)
  415. ->count();
  416. $orderRentWaitPayNum = OrderRent::query()
  417. ->where(AdminMerchant::getMerchantWhere())
  418. ->filter($orderRentFilter)
  419. ->where('status', OrderRent::STATUS_CLOSE_RENT_BIKE)
  420. ->whereIn('area_id', $area_ids)
  421. ->count();
  422. $wiatNum = bcadd($orderWaitPayNum, $orderRentWaitPayNum);
  423. $bikeTotal = Bike::query()
  424. ->where(AdminMerchant::getMerchantWhere())
  425. ->filter($bikeFilter)
  426. ->where('put_status', Bike::PUT_STATUS_YES)
  427. ->whereIn('put_area_id', $area_ids)
  428. ->count();
  429. $totalUsers = User::query()
  430. ->where(AdminMerchant::getMerchantWhere())
  431. ->filter($userFilter)
  432. ->whereIn('register_area_id', $area_ids)
  433. ->count();
  434. $riddingCardOrderTotalProfit = CardRidingOrder::query()
  435. ->where(AdminMerchant::getMerchantWhere())
  436. ->whereIn('area_id', $area_ids)
  437. ->filter($cardRidingOrderFilter)
  438. ->where('pay_status', CardRidingOrder::PAY_STATUS_OK)
  439. ->sum('pay_money');
  440. $rechargeOrderTotalProfit = RechargeOrder::query()
  441. ->where(AdminMerchant::getMerchantWhere())
  442. ->whereIn('area_id', $area_ids)
  443. ->filter($rechargeOrderFilter)
  444. ->where('pay_status', RechargeOrder::PAY_STATUS_OK)
  445. ->sum('pay_money');
  446. $depositCardTotalProfit = DepositCardOrder::query()
  447. ->where(AdminMerchant::getMerchantWhere())
  448. ->whereIn('area_id', $area_ids)
  449. ->filter($depositCardOrderFilter)
  450. ->where('pay_status', DepositCardOrder::PAY_STATUS_OK)
  451. ->sum('pay_money');
  452. $data = [
  453. 'totalProfit' => bcadd($orderTotalProfit, $orderRentTotalProfit, 2) ?? 0, // 新增收益
  454. 'depositTotal' => $depositTotal ?? 0, // 新增押金
  455. 'orderTotalProfit' => $orderTotalProfit ?? 0, // 新增普通订单收入 // 骑行花费
  456. 'orderTotal' => $orderTotal ?? 0, // 新增普通订单数量
  457. 'orderDispatchTotalProfit' => $orderDispatchTotalProfit ?? 0, // 新增普通订单调度费收入 // 调度费
  458. 'orderRentTotalProfit' => $orderRentTotalProfit ?? 0, // 新增日租订单收入
  459. 'orderRentTotal' => $orderRentTotal ?? 0, // 新增日租订单数量
  460. 'orderRentDispatchTotalProfit' => $orderRentDispatchTotalProfit ?? 0, // 新增日租订单调度费收入
  461. 'userTotalCardOk' => $userTotalCardOk ?? 0, // 新增身份认证用户
  462. 'userTotal' => $totalUsers ?? 0, // 总用户数
  463. 'userDepositTotal' => $userDepositTotal ?? 0, // 总缴纳押金用户数
  464. 'wiatPayTotal' => $wiatPayTotal ?? 0, //总待支付
  465. 'wiatNum' => $wiatNum ?? 0, //总待支付数量
  466. 'bikeTotal' => $bikeTotal ?? 0, // 总投放车辆
  467. 'days' => abs($days), // 天数
  468. 'riddingCardOrderTotalProfit' => $riddingCardOrderTotalProfit ?? 0, // 骑行卡收益
  469. 'rechargeOrderTotalProfit' => $rechargeOrderTotalProfit ?? 0, // 充值订单收益
  470. 'depositCardTotalProfit' => $depositCardTotalProfit ?? 0, // 免押金卡收益
  471. 'activityTotalProfit' => bcadd(bcadd($riddingCardOrderTotalProfit,$rechargeOrderTotalProfit,2),$depositCardTotalProfit,2), // 活动总收益
  472. ];
  473. return $this->ok($data);
  474. }
  475. /**
  476. * orderDetail 订单详情
  477. *
  478. * @param Request $request
  479. * @return \Illuminate\Http\JsonResponse
  480. * @author Fx
  481. *
  482. */
  483. public function orderDetail(Request $request)
  484. {
  485. $order_id = $request->get('order_id') ?? '';
  486. if (empty($order_id)) return $this->error('参数错误');
  487. $order = Order::query()->where(AdminMerchant::getMerchantWhere())->where('id',$order_id)->first();
  488. if (empty($order)) return $this->error('找不到该订单,参数错误');
  489. $orderLocations = [];
  490. $wx_orderLocations = [];
  491. // 订单轨迹
  492. $locationsLog = LocationsLog::query()->where('order_id', (int)$order_id)->where('is_rent', LocationsLog::RENT_NO)->whereBetween('latitude', [3, 53])->whereBetween('longitude', [73, 136])->orderBy('created_at', 'asc')->get();
  493. if (!empty($locationsLog)) {
  494. foreach ($locationsLog as $vv) {
  495. $orderLocations[] = [$vv->longitude, $vv->latitude];
  496. $wx_orderLocations[] = ['longitude' => $vv->longitude, 'latitude' => $vv->latitude];
  497. }
  498. }
  499. // Log::info($orderLocations);
  500. $data = [
  501. 'order_status' => Order::$statusMaps[$order->status],
  502. 'start_use_bike_time' => date('Y/m/d H:i:s', strtotime($order->start_use_bike_time)),
  503. 'end_use_bike_time' => $order->end_use_bike_time ? date('Y/m/d H:i:s', strtotime($order->end_use_bike_time)) : '',
  504. 'pay_money' => $order->pay_money,
  505. 'dispatch_money' => $order->dispatch_money,
  506. 'time_money' => $order->time_money,
  507. 'bike_no' => $order->bike_no,
  508. 'bike_id' => $order->bike_id,
  509. 'user_id' => $order->user_id,
  510. 'nickname' => $order->users->nickname ?? '',
  511. 'mobile' => $order->users->mobile ?? '',
  512. 'orderLocations' => $orderLocations,
  513. 'start_location' => empty($orderLocations) ? [] : current($orderLocations),
  514. 'end_location' => empty($orderLocations) ? [] : end($orderLocations),
  515. 'wx_orderLocations' => $wx_orderLocations,
  516. 'wx_start_location' => empty($wx_orderLocations) ? [] : current($wx_orderLocations),
  517. 'wx_end_location' => empty($wx_orderLocations) ? [] : end($wx_orderLocations),
  518. 'preferential_type_name' => $order->preferential_type_name, // 优惠方式
  519. 'preferential_money' => $order->preferential_money,// 优惠金额
  520. 'card_preferential_money' => $order->card_preferential_money,// 骑行卡优惠金额
  521. 'coupon_preferential_money' => $order->coupon_preferential_money,// 优惠券优惠金额
  522. 'is_coupon_name' => Order::$couponMaps[$order->is_coupon] ,// 优惠券优惠
  523. 'walletLogs' => $order->walletLogs,
  524. 'order_bike_operates' => $order->order_bike_operates,
  525. 'remark' => $order->remark ?? '',
  526. //'center_location' => GetCenterFromDegrees([['lat'=>$orderLocations[0][1],'lng'=>$orderLocations[0][0]],['lat'=>end($orderLocations)[1],'lng'=>end($orderLocations)[0]]])
  527. ];
  528. return $this->ok($data);
  529. }
  530. /**
  531. * orderLocation 订单轨迹
  532. *
  533. * @param Request $request
  534. * @return \Illuminate\Http\JsonResponse
  535. * @author Fx
  536. *
  537. */
  538. public function orderLocation(Request $request)
  539. {
  540. $order_id = $request->get('order_id') ?? '';
  541. if (empty($order_id)) return $this->error('参数错误');
  542. $orderLocations = [];
  543. $locationsTimes = [];
  544. try {
  545. $locationsLog = LocationsLog::query()->where('order_id', (int)$order_id)->where('is_rent', LocationsLog::RENT_NO)->whereBetween('latitude', [3, 53])->whereBetween('longitude', [73, 136])->orderBy('created_at', 'asc')->get();
  546. } catch (\Exception $exception) {
  547. Log::info($exception->getMessage());
  548. }
  549. if (!empty($locationsLog)) {
  550. foreach ($locationsLog as $vv) {
  551. $orderLocations[] = [$vv->longitude, $vv->latitude];
  552. $locationsTimes[] = Carbon::parse($vv->created_at)->format('Y-m-d H:i:s');
  553. }
  554. }
  555. $data = [
  556. 'orderLocations' => $orderLocations,
  557. 'locationsTimes' => $locationsTimes,
  558. ];
  559. return $this->ok($data);
  560. }
  561. /**
  562. * heatMap 热力图
  563. *
  564. * @param OrderFilter $orderFilter
  565. * @return \Illuminate\Http\JsonResponse
  566. * @author Fx
  567. *
  568. */
  569. public function heatMap(OrderFilter $orderFilter)
  570. {
  571. $today = Carbon::today()->subMonth();
  572. //whereIn('area_id',self::$areaIds)->
  573. $order = Order::query()->filter($orderFilter)->where('created_at', '>', $today)->get();
  574. $data1 = [];
  575. $data2 = [];
  576. if (!empty($order)) {
  577. foreach ($order as $v) {
  578. $location = json_decode($v->start_use_bike_location);
  579. $location2 = json_decode($v->end_use_bike_location);
  580. $data1[] = ['lat' => $location->latitude, 'lng' => $location->longitude, 'count' => 3];
  581. if(!empty($location2)){
  582. $data2[] = ['lat' => $location2->latitude, 'lng' => $location2->longitude, 'count' => 3];
  583. }
  584. }
  585. }
  586. $data = [
  587. 'start' => $data1,
  588. 'end' => $data2
  589. ];
  590. return $this->ok($data);
  591. }
  592. /**
  593. * newOrderChart 新订单统计图
  594. *
  595. * @param Request $request
  596. * @param OrderFilter $orderFilter
  597. * @return array
  598. * @author Fx
  599. *
  600. */
  601. // public function newOrderChart(Request $request, OrderFilter $orderFilter)
  602. // {
  603. // $days = $request->get('days') ?? '';
  604. // $areaId = $request->get('area_id') ?? '';
  605. // if (empty($days) || empty($areaId)) return $this->error('缺少参数');
  606. // if (empty($days)) return $this->error('缺少参数');
  607. // $newOrders = Order::query()
  608. // ->filter($orderFilter)
  609. // ->where('status', Order::STATUS_COMPLETE_ORDER);
  610. //
  611. //// $admin_id = Admin::user()->id;
  612. //// if (!Admin::isAdministrator()) {
  613. //// $area_ids = AdminUser::getAreaIdsByAdminId($admin_id);
  614. //// if (count($area_ids) !== 0) {
  615. //// $newOrders = $newOrders->whereIn('area_id', $area_ids);
  616. //// } else {
  617. //// $area_id = AdminUserArea::query()->where('admin_id', $admin_id)->first('area_id');
  618. //// $area_id = $area_id ?? 0;
  619. //// $newOrders = $newOrders->where('area_id', $area_id);
  620. //// }
  621. //// }
  622. //
  623. // switch ($days) {
  624. // case 'today':
  625. // $today = Carbon::today();
  626. // $newOrders = $newOrders->where('created_at', '>', $today)
  627. // ->selectRaw('DATE_FORMAT(created_at,"%m-%d %H:00") as date,count(id) as value,sum(pay_money) as moneys')
  628. // ->groupBy('date')->get()->toArray();
  629. // // 有数据得数组
  630. // $newOrdersKeyVal = [];
  631. // if (!empty($newOrders)) {
  632. // foreach ($newOrders as $v) {
  633. // $newOrdersKeyVal[$v['date']] = $v['value'];
  634. // }
  635. // }
  636. // // 为0得数组
  637. // $i = Carbon::now()->format('H');
  638. // $arr = [];
  639. // for ($i; $i >= 0; $i--) {
  640. // $str = Carbon::now()->subHours($i)->format('m-d H:00');
  641. // $arr[$str] = 0;
  642. // }
  643. // //合并
  644. // $merge = array_merge($arr, $newOrdersKeyVal);
  645. // $data = [];
  646. // foreach ($merge as $key=>$value){
  647. // $data[]=['date'=>$key,'value'=>$value];
  648. // }
  649. //
  650. // break;
  651. // case 'threeDays':
  652. // $i = 2;
  653. // break;
  654. // case 'sevenDays':
  655. // $i = 6;
  656. //
  657. // break;
  658. // case 'fifteenDays':
  659. // $i = 14;
  660. // break;
  661. // case 'thirtyDays':
  662. // $i = 29;
  663. // break;
  664. // default:
  665. // return $this->error('参数错误');
  666. //
  667. // }
  668. // if($days !== 'today'){
  669. // $paramDays = Carbon::today()->subDays($i);
  670. //
  671. // // 赋值一个值为0得数组
  672. // $arr = [];
  673. // for ($i ; $i >= 0; $i--){
  674. // $str = Carbon::today()->subDays($i)->format('Y/m/d');
  675. // $arr[$str] = 0;
  676. // }
  677. //
  678. // // 有数据得数组
  679. // $newOrders = $newOrders->where('created_at', '>', $paramDays)
  680. // ->selectRaw('DATE_FORMAT(created_at,"%Y/%m/%d") as date,count(id) as value,sum(pay_money) as moneys')
  681. // ->groupBy('date')->get()->toArray();
  682. // $newOrdersKeyVal = [];
  683. // $newOrdersKeyValMoney = [];
  684. // if(!empty($newOrders)){
  685. // foreach ($newOrders as $v){
  686. // $newOrdersKeyVal[$v['date']] = $v['value'];
  687. // $newOrdersKeyValMoney[$v['date']] = $v['moneys'];
  688. // }
  689. // }
  690. // // 合并覆盖0
  691. // $merge = array_merge($arr,$newOrdersKeyVal);
  692. // $mergemoney = array_merge($arr,$newOrdersKeyValMoney);
  693. // // return $this->ok($merge);
  694. //
  695. // // 重组结构
  696. // $data = [];
  697. // foreach ($merge as $ks=>$vs){
  698. // $data[]=['date'=>$ks,'value'=>$vs,'moneys'=>$mergemoney[$ks]];
  699. // }
  700. // }
  701. //
  702. // return $this->ok($data);
  703. // }
  704. public function orderChart($days, $orderFilter, $dispatch_money = false)
  705. {
  706. $newOrders = Order::query()
  707. ->where(AdminMerchant::getMerchantWhere())
  708. ->filter($orderFilter)
  709. ->where('status', Order::STATUS_COMPLETE_ORDER);
  710. if ($dispatch_money) {
  711. $newOrders = $newOrders->where('dispatch_money', '>', 0);
  712. }
  713. $admin_id = Admin::user()->id;
  714. if (!Admin::isAdministrator()) {
  715. $area_ids = AdminUser::getAreaIdsByAdminId($admin_id);
  716. if (count($area_ids) !== 0) {
  717. $newOrders = $newOrders->whereIn('area_id', $area_ids);
  718. } else {
  719. $area_id = AdminUserArea::query()->where('admin_id', $admin_id)->first('area_id');
  720. $area_id = $area_id ?? 0;
  721. $newOrders = $newOrders->where('area_id', $area_id);
  722. }
  723. }
  724. switch ($days) {
  725. case 'today':
  726. $today = Carbon::today();
  727. $newOrders = $newOrders->where('created_at', '>', $today)
  728. ->selectRaw('DATE_FORMAT(created_at,"%m-%d %H:00") as date,count(id) as value')
  729. ->groupBy('date')->get()->toArray();
  730. // 有数据得数组
  731. $newOrdersKeyVal = [];
  732. if (!empty($newOrders)) {
  733. foreach ($newOrders as $v) {
  734. $newOrdersKeyVal[$v['date']] = $v['value'];
  735. }
  736. }
  737. // 为0得数组
  738. $i = Carbon::now()->format('H');
  739. $arr = [];
  740. for ($i; $i >= 0; $i--) {
  741. $str = Carbon::now()->subHours($i)->format('m-d H:00');
  742. $arr[$str] = 0;
  743. }
  744. //合并
  745. $merge = array_merge($arr, $newOrdersKeyVal);
  746. $data = [];
  747. foreach ($merge as $key => $value) {
  748. $data[] = ['date' => $key, 'value' => $value];
  749. }
  750. break;
  751. case 'threeDays':
  752. $i = 2;
  753. break;
  754. case 'sevenDays':
  755. $i = 6;
  756. break;
  757. case 'fifteenDays':
  758. $i = 14;
  759. break;
  760. case 'thirtyDays':
  761. $i = 29;
  762. break;
  763. default:
  764. return [];
  765. }
  766. if ($days !== 'today') {
  767. $paramDays = Carbon::today()->subDays($i);
  768. // 赋值一个值为0得数组
  769. $arr = [];
  770. for ($i; $i >= 0; $i--) {
  771. $str = Carbon::today()->subDays($i)->format('Y/m/d');
  772. $arr[$str] = 0;
  773. }
  774. // 有数据得数组
  775. $newOrders = $newOrders->where('created_at', '>', $paramDays)
  776. ->selectRaw('DATE_FORMAT(created_at,"%Y/%m/%d") as date,count(id) as value')
  777. ->groupBy('date')->get()->toArray();
  778. $newOrdersKeyVal = [];
  779. if (!empty($newOrders)) {
  780. foreach ($newOrders as $v) {
  781. $newOrdersKeyVal[$v['date']] = $v['value'];
  782. }
  783. }
  784. // 合并覆盖0
  785. $merge = array_merge($arr, $newOrdersKeyVal);
  786. // 重组结构
  787. $data = [];
  788. foreach ($merge as $ks => $vs) {
  789. $data[] = ['date' => $ks, 'value' => $vs];
  790. }
  791. }
  792. return $data;
  793. }
  794. public function newOrderChart(Request $request, OrderFilter $orderFilter)
  795. {
  796. $days = $request->get('days') ?? '';
  797. if (empty($days)) return $this->error('缺少参数');
  798. $newOrderChart = $this->orderChart($days, $orderFilter);
  799. $dispatchMoneyNewOrderChart = $this->orderChart($days, $orderFilter, true);
  800. return $this->ok([
  801. [
  802. 'name' => '总订单数',
  803. 'data' => $newOrderChart
  804. ], [
  805. 'name' => '有调度费的订单数',
  806. 'data' => $dispatchMoneyNewOrderChart
  807. ],
  808. ]);
  809. // return $this->ok([
  810. // $newOrderChart,$dispatchMoneyNewOrderChart
  811. // ]);
  812. }
  813. public function profitPolygonalChart($days, $filter, $model, $money = 'pay_money')
  814. {
  815. if (empty($days)) return $this->error('缺少参数');
  816. $newOrders = $model
  817. ->filter($filter)
  818. ->where('pay_status', 1);
  819. $admin_id = Admin::user()->id;
  820. if (!Admin::isAdministrator()) {
  821. $area_ids = AdminUser::getAreaIdsByAdminId($admin_id);
  822. if (count($area_ids) !== 0) {
  823. $newOrders = $newOrders->whereIn('area_id', $area_ids);
  824. } else {
  825. $area_id = AdminUserArea::query()->where('admin_id', $admin_id)->first('area_id');
  826. $area_id = $area_id ?? 0;
  827. $newOrders = $newOrders->where('area_id', $area_id);
  828. }
  829. }
  830. switch ($days) {
  831. case 'today':
  832. $today = Carbon::today();
  833. $newOrders = $newOrders->where('pay_time', '>', $today)
  834. ->selectRaw("DATE_FORMAT(pay_time,'%m-%d %H:00') as date,sum($money) as value")
  835. ->groupBy('date')->get()->toArray();
  836. // 有数据得数组
  837. $newOrdersKeyVal = [];
  838. if (!empty($newOrders)) {
  839. foreach ($newOrders as $v) {
  840. $newOrdersKeyVal[$v['date']] = $v['value'];
  841. }
  842. }
  843. // 为0得数组
  844. $i = Carbon::now()->format('H');
  845. $arr = [];
  846. for ($i; $i >= 0; $i--) {
  847. $str = Carbon::now()->subHours($i)->format('m-d H:00');
  848. $arr[$str] = 0;
  849. }
  850. //合并
  851. $merge = array_merge($arr, $newOrdersKeyVal);
  852. $data = [];
  853. foreach ($merge as $key => $value) {
  854. $data[] = ['date' => $key, 'value' => $value];
  855. }
  856. break;
  857. case 'threeDays':
  858. $i = 2;
  859. break;
  860. case 'sevenDays':
  861. $i = 6;
  862. break;
  863. case 'fifteenDays':
  864. $i = 14;
  865. break;
  866. case 'thirtyDays':
  867. $i = 29;
  868. break;
  869. default:
  870. return $this->error('参数错误');
  871. }
  872. if ($days !== 'today') {
  873. $paramDays = Carbon::today()->subDays($i);
  874. // 赋值一个值为0得数组
  875. $arr = [];
  876. for ($i; $i >= 0; $i--) {
  877. $str = Carbon::today()->subDays($i)->format('Y/m/d');
  878. $arr[$str] = 0;
  879. }
  880. // 有数据得数组
  881. $newOrders = $newOrders->where('pay_time', '>', $paramDays)
  882. ->selectRaw("DATE_FORMAT(pay_time,'%Y/%m/%d') as date,sum($money) as value")
  883. ->groupBy('date')->get()->toArray();
  884. $newOrdersKeyVal = [];
  885. if (!empty($newOrders)) {
  886. foreach ($newOrders as $v) {
  887. $newOrdersKeyVal[$v['date']] = $v['value'];
  888. }
  889. }
  890. // 合并覆盖0
  891. $merge = array_merge($arr, $newOrdersKeyVal);
  892. // 重组结构
  893. $data = [];
  894. foreach ($merge as $ks => $vs) {
  895. $data[] = ['date' => $ks, 'value' => $vs];
  896. }
  897. }
  898. return $data;
  899. }
  900. public function profitChart(Request $request, OrderFilter $orderFilter, RechargeOrderFilter $rechargeOrderFilter, CardRidingOrderFilter $cardRidingOrderFilter, DepositCardOrderFilter $depositCardOrderFilter)
  901. {
  902. $days = $request->get('days') ?? '';
  903. $ordersChart = $this->profitPolygonalChart($days, $orderFilter, Order::query()->where(AdminMerchant::getMerchantWhere()));
  904. $ordersDispatchMoneyChart = $this->profitPolygonalChart($days, $orderFilter, Order::query()->where(AdminMerchant::getMerchantWhere()), 'dispatch_money');
  905. $rechargeOrdersChart = $this->profitPolygonalChart($days, $rechargeOrderFilter, RechargeOrder::query()->where(AdminMerchant::getMerchantWhere()));
  906. $cardRidingOrdersChart = $this->profitPolygonalChart($days, $cardRidingOrderFilter, CardRidingOrder::query()->where(AdminMerchant::getMerchantWhere()));
  907. $depositCardOrdersChart = $this->profitPolygonalChart($days, $depositCardOrderFilter, DepositCardOrder::query()->where(AdminMerchant::getMerchantWhere()));
  908. $total = [];
  909. foreach ($ordersChart as $k => $v) {
  910. $total[] = [
  911. 'date' => $v['date'],
  912. 'value' => bcadd(bcadd(bcadd($v['value'], $rechargeOrdersChart[$k]['value'], 2), $cardRidingOrdersChart[$k]['value'], 2), $depositCardOrdersChart[$k]['value'], 2)
  913. ];
  914. }
  915. if (Admin::isNormalAdministrator() || Admin::isAdministrator()){
  916. return $this->ok([
  917. [
  918. 'name' => '普通订单收益',
  919. 'data' => $ordersChart
  920. ],
  921. [
  922. 'name' => '订单调度费收益',
  923. 'data' => $ordersDispatchMoneyChart
  924. ],
  925. [
  926. 'name' => '充值收益',
  927. 'data' => $rechargeOrdersChart
  928. ],
  929. [
  930. 'name' => '骑行卡收益',
  931. 'data' => $cardRidingOrdersChart
  932. ],
  933. [
  934. 'name' => '免押金卡收益',
  935. 'data' => $depositCardOrdersChart
  936. ],
  937. [
  938. 'name' => '总收益',
  939. 'data' => $total
  940. ],
  941. ]);
  942. }else{
  943. return $this->ok([]);
  944. }
  945. }
  946. /**
  947. * 前七天小时订单统计
  948. * @return \Illuminate\Http\JsonResponse
  949. * User: Mead
  950. */
  951. public function hourOrderNumber(Request $request,OrderFilter $filter)
  952. {
  953. $day = [
  954. ["num" => 0, "hour" => 0],
  955. ["num" => 0, "hour" => 1],
  956. ["num" => 0, "hour" => 2],
  957. ["num" => 0, "hour" => 3],
  958. ["num" => 0, "hour" => 4],
  959. ["num" => 0, "hour" => 5],
  960. ["num" => 0, "hour" => 6],
  961. ["num" => 0, "hour" => 7],
  962. ["num" => 0, "hour" => 8],
  963. ["num" => 0, "hour" => 9],
  964. ["num" => 0, "hour" => 10],
  965. ["num" => 0, "hour" => 11],
  966. ["num" => 0, "hour" => 12],
  967. ["num" => 0, "hour" => 13],
  968. ["num" => 0, "hour" => 14],
  969. ["num" => 0, "hour" => 15],
  970. ["num" => 0, "hour" => 16],
  971. ["num" => 0, "hour" => 17],
  972. ["num" => 0, "hour" => 18],
  973. ["num" => 0, "hour" => 19],
  974. ["num" => 0, "hour" => 20],
  975. ["num" => 0, "hour" => 21],
  976. ["num" => 0, "hour" => 22],
  977. ["num" => 0, "hour" => 23]
  978. ];
  979. $weeks = [];
  980. $area_ids = self::$areaIds;
  981. for ($i = 1, $c = 7; $i < 7; $i++, $c--) {
  982. $now = Carbon::parse("-{$i}day");
  983. $date = $now->toDateString();
  984. $key = "{$date}-hour-order-num";
  985. $area_id = $request->get('area_id') ?? '';
  986. if(!empty($area_id)){
  987. $key = $key .'-area_id:'. $area_id;
  988. }
  989. // Cache::forget($key);
  990. $weeks["{$date}"] = Cache::remember($key, Carbon::parse("+{$c}day")->diffInMinutes(Carbon::now()), function () use ($date, $day,$filter,$area_ids) {
  991. return array_replace($day, Order::query()->where(AdminMerchant::getMerchantWhere())->filter($filter)->whereDate("created_at", $date)->whereIn('area_id',$area_ids)->select(DB::raw("count(*) as num,DATE_FORMAT(created_at,'%H') as hour"))->groupBy("hour")->get()->mapWithKeys(function ($item) {
  992. $arr = [
  993. 'num' => (integer)$item->num,
  994. 'hour' => (integer)$item->hour,
  995. ];
  996. return [(integer)$item->hour => $arr];
  997. })->toArray());
  998. });
  999. }
  1000. $data = [
  1001. 'date' => [],
  1002. 'data' => []
  1003. ];
  1004. foreach ($weeks as $k => $v) {
  1005. $data['date'][] = $k;
  1006. $data['data'][$k] = [];
  1007. foreach ($v as $value) {
  1008. array_push($data['data'][$k], $value['num']);
  1009. }
  1010. }
  1011. // dd($data);
  1012. return $this->ok($data);
  1013. }
  1014. }