ShopTransformer.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Repositories\Transformers;
  11. use App\Models\Order;
  12. use App\Models\Shop;
  13. use App\Repositories\Enums\OrderStatusEnum;
  14. use League\Fractal\TransformerAbstract;
  15. class ShopTransformer extends TransformerAbstract
  16. {
  17. public function transform(Shop $shop)
  18. {
  19. $data = [
  20. 'id' => $shop->id,
  21. 'name' => $shop->name,
  22. 'address' => $shop->address,
  23. 'mobile' => $shop->mobile,
  24. 'cover' => $shop->cover,
  25. 'lat' => $shop->lat,
  26. 'lng' => $shop->lng,
  27. 'intro' => $shop->intro,
  28. 'opening_hours' => $shop->opening_hours,
  29. 'contact_name' => $shop->contact_name,
  30. 'contact_mobile' => $shop->contact_mobile,
  31. 'royalties' => $shop->royalties,
  32. 'a_minute_money' => $shop->a_minute_money,
  33. 'b_minute_money' => $shop->b_minute_money,
  34. 'ab_minute_money' => $shop->ab_minute_money,
  35. 'times' => $shop->times,
  36. 'device_nums' => $shop->device_nums,
  37. 'distance' => $shop->distance ?? 0,
  38. 'day_money' => Order::query()->whereDate('pay_time', date("Y-m-d"))->where('shop_id', $shop->id)->where('status', OrderStatusEnum::ORDER_OVER)->sum('pay_money'),
  39. 'work_time' => Order::query()->whereDate('pay_time', date("Y-m-d"))->where('shop_id', $shop->id)->where('status', OrderStatusEnum::ORDER_OVER)->sum('work_time')
  40. ];
  41. return $data;
  42. }
  43. }