StoreDeliveryController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\store;
  12. use app\Request;
  13. use app\services\order\store\BranchOrderServices;
  14. use app\services\store\DeliveryServiceServices;
  15. use app\services\store\SystemStoreServices;
  16. use app\services\store\SystemStoreStaffServices;
  17. use app\services\user\UserServices;
  18. /**
  19. * 配送员
  20. * Class StoreDeliveryController
  21. * @package app\controller\store\staff
  22. */
  23. class StoreDeliveryController
  24. {
  25. /**
  26. * @var DeliveryServiceServices
  27. */
  28. protected $services;
  29. /**
  30. * StoreDeliveryController constructor.
  31. * @param DeliveryServiceServices $services
  32. */
  33. public function __construct(DeliveryServiceServices $services)
  34. {
  35. $this->services = $services;
  36. }
  37. /**
  38. * 获取配送员信息
  39. * @param Request $request
  40. * @return mixed
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\DbException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. */
  45. public function info(Request $request, SystemStoreServices $storeServices, UserServices $userServices)
  46. {
  47. $uid = (int)$request->uid();
  48. $deliveryInfo = $this->services->getDeliveryInfoByUid($uid)->toArray();
  49. $store_ids = $this->services->getDeliveryStoreIds($uid, 1,'relation_id');
  50. $store_info = [];
  51. if ($store_ids) {
  52. $store_info = $storeServices->getColumn([['id', 'in', $store_ids], ['is_show', '=', 1], ['is_del', '=', 0]], 'id,name');
  53. }
  54. $deliveryInfo['store_info'] = $store_info;
  55. $deliveryInfo['user_nickname'] = $userServices->value(['uid' => $uid], 'nickname');
  56. return app('json')->success($deliveryInfo);
  57. }
  58. /**
  59. * 获取所有配送员列表
  60. * @param DeliveryServiceServices $services
  61. * @return mixed
  62. */
  63. public function getDeliveryAll(Request $request, SystemStoreStaffServices $staffServices)
  64. {
  65. $uid = (int)$request->uid();
  66. $staffInfo = $staffServices->getStaffInfoByUid($uid);
  67. $list = $this->services->getDeliveryList(1, (int)$staffInfo['store_id']);
  68. return app('json')->success($list['list']);
  69. }
  70. /**
  71. * 配送员数据统计
  72. * @param Request $request
  73. * @return mixed
  74. */
  75. public function statistics(Request $request)
  76. {
  77. [$store_id, $time] = $request->getMore([
  78. ['store_id', 0],
  79. ['data', '', '', 'time'],
  80. ], true);
  81. $uid = (int)$request->uid();
  82. $data = $this->services->getStoreData($uid, $store_id, $time);
  83. return app('json')->successful($data);
  84. }
  85. /**
  86. * 配送统计列表数据
  87. * @param Request $request
  88. * @return mixed
  89. */
  90. public function data(Request $request, BranchOrderServices $orderServices)
  91. {
  92. [$store_id, $time] = $request->getMore([
  93. ['store_id', 0],
  94. ['data', '', '', 'time'],
  95. ], true);
  96. $uid = (int)$request->uid();
  97. $this->services->getDeliveryInfoByUid($uid, $store_id ? 1: 0, (int)$store_id);
  98. $where = ['delivery_uid' => $uid, 'time' => $time];
  99. if ($store_id) {
  100. $where['store_id'] = $store_id;
  101. }
  102. $data = $orderServices->getOrderDataPriceCount($where);
  103. return app('json')->successful($data);
  104. }
  105. /**
  106. * 配送订单列表
  107. * @param Request $request
  108. * @return mixed
  109. */
  110. public function orderList(Request $request, BranchOrderServices $orderServices)
  111. {
  112. [$type] = $request->getMore([
  113. ['type', 1]
  114. ], true);
  115. $uid = (int)$request->uid();
  116. $where = ['delivery_uid' => $uid, 'status' => 9, 'is_del' => 0, 'is_system_del' => 0, 'paid' => 1, 'refund_status' => [0, 3]];
  117. if ($type == 1) {
  118. $where['status'] = 2;
  119. }
  120. $list = $orderServices->getStoreOrderList($where, ['*'], ['pink', 'store' => function ($query) {
  121. $query->field('id,name,address,detailed_address');
  122. }]);
  123. $data = [];
  124. $where['status'] = 2;
  125. $data['unsend'] = $orderServices->count($where);
  126. $where['status'] = 9;
  127. $data['send'] = $orderServices->count($where);
  128. return app('json')->successful(compact('data', 'list'));
  129. }
  130. }