You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Model\v3\Market;
  4. use App\Model\v3\OrderMain;
  5. use Hyperf\Di\Annotation\Inject;
  6. use App\Service\v3\Interfaces\HorsemanServiceInterface;
  7. use Hyperf\Utils\ApplicationContext;
  8. use App\Constants\v3\SsdbKeys;
  9. use App\TaskWorker\SSDBTask;
  10. use App\Constants\v3\ErrorCode;
  11. use App\Exception\ErrorCodeException;
  12. class HorsemanService implements HorsemanServiceInterface
  13. {
  14. public function do()
  15. {
  16. // TODO: Implement do() method.
  17. }
  18. public function check()
  19. {
  20. // TODO: Implement check() method.
  21. }
  22. public function undo()
  23. {
  24. // TODO: Implement undo() method.
  25. }
  26. public function getOrderList($employeesId,$page=1, $pagesize=10)
  27. {
  28. $builder = OrderMain::query()->where(['state' => 3,'horseman_id' => $employeesId]);
  29. $paginate = $builder->orderBy('created_at', 'desc')->paginate($pagesize);
  30. $orders = $paginate->toArray();
  31. return [
  32. 'has_more_pages' => $paginate->hasMorePages(),
  33. 'order_list' => $orders['data']
  34. ];
  35. }
  36. /**
  37. * 记录骑手坐标
  38. */
  39. public function setHorsemanCoordinate($employeesId,$coordinate){
  40. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  41. if(false === $ssdb->exec('set', SsdbKeys::HORSEMAN_COORDINATE.$employeesId,$coordinate)) {
  42. return false;
  43. }
  44. return true;
  45. }
  46. /**
  47. * 获取骑手坐标
  48. */
  49. public function getHorsemanCoordinate($employeesId){
  50. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  51. $params = $ssdb->exec('get', SsdbKeys::HORSEMAN_COORDINATE.$employeesId);
  52. if ((false === $params) || empty($params)) {
  53. throw new ErrorCodeException(ErrorCode::HORSEMAN_COORDINATE_FAIL, '骑手正在配送中');
  54. }
  55. return $params;
  56. }
  57. /**
  58. * 获取订单起止坐标
  59. */
  60. public function getOrderCoordinate($globalOrderId){
  61. //获取订单信息
  62. $order = OrderMain::where('global_order_id',$globalOrderId)
  63. ->select(
  64. 'lat',
  65. 'lng',
  66. 'state',
  67. 'market_id'
  68. )
  69. ->first();
  70. if($order->state != 3)
  71. {
  72. return false;
  73. }
  74. //获取市场信息
  75. $market = Market::where('id',$order->market_id)
  76. ->select(
  77. 'lat',
  78. 'lng'
  79. )
  80. ->first();
  81. $res = [
  82. 'order' => $order,
  83. 'market' => $market
  84. ];
  85. return $res;
  86. }
  87. }