链街Dcat后台
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.

80 lines
2.4 KiB

6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
4 years ago
6 years ago
4 years ago
5 years ago
5 years ago
4 years ago
6 years ago
6 years ago
  1. <?php
  2. namespace App\Admin\Forms;
  3. use App\Admin\Common\Auth;
  4. use App\Admin\Common\Rpc;
  5. use App\Libs\SsdbClient;
  6. use App\Models\ImsCjdcMarket;
  7. use App\Models\ImsCjdcOrderMain;
  8. use App\Models\v3\LanzuEmployees;
  9. use Dcat\Admin\Widgets\Form;
  10. use Symfony\Component\HttpFoundation\Response;
  11. class SelectHorseman extends Form
  12. {
  13. /**
  14. * Handle the form request.
  15. *
  16. * @param array $input
  17. *
  18. * @return Response
  19. */
  20. protected $orderId;
  21. public function handle(array $input)
  22. {
  23. $current_page = $input['current_page'] ?? 1;
  24. if ($this->selectHorseman($input)) {
  25. return $this->success('操作成功',"order?page={$current_page}");
  26. } else {
  27. return $this->error('操作失败');
  28. }
  29. }
  30. /**
  31. * 注:此方法在app/Http/Controllers/GrabOrderController.php中也有调用,修改需要注意
  32. */
  33. public function selectHorseman(array $input): bool
  34. {
  35. $hid = $input['horseman_id'];
  36. $oid = $input['order_id'];
  37. $horseman = LanzuEmployees::getName($hid);//骑手名称
  38. $time = time();
  39. $result = ImsCjdcOrderMain::where(['id' => $oid, 'horseman_id' => 0])
  40. ->update([
  41. 'shipping_type' => 1,
  42. 'horseman_id' => $hid,
  43. 'delivery_start_time' => $time,
  44. 'shipping_name' => $horseman,
  45. 'updated_at' => $time,
  46. ]);
  47. if ($result){
  48. //>>1.指定骑手后,初始化骑手位置,默认将市场经纬做为骑手默认经纬
  49. $row = ImsCjdcOrderMain::where('id',$oid)->select('market_id','global_order_id')->first();
  50. $mid = $row->market_id;
  51. $market = ImsCjdcMarket::where('id',$mid)->first();
  52. $ssdb = SsdbClient::client(env('SSDB_HOST'), env('SSDB_PORT'));
  53. $coordinate = $market->lng.','.$market->lat;
  54. $ssdb->set("horseman_coordinate_{$hid}",$coordinate);
  55. //>>2.配送开始后,给用户发送消息通知
  56. Rpc::onlineDeliveryStart($row->global_order_id);
  57. return true;
  58. } else {
  59. return false;
  60. }
  61. }
  62. /**
  63. * Build a form here.
  64. */
  65. public function form()
  66. {
  67. $this->select('horseman_id','配送员')
  68. ->options(LanzuEmployees::getHorseman(Auth::getMarket()))
  69. ->required();
  70. $this->hidden('order_id');
  71. $this->hidden('current_page');
  72. }
  73. }