链街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.

238 lines
8.9 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
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
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
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\Admin\Controllers;
  3. use App\Admin\Actions\Tools\ShowOrderStateHandle;
  4. use App\Admin\Common\Auth;
  5. use App\Admin\Common\Map;
  6. use App\Admin\Common\Rpc;
  7. use App\Admin\Extensions\CheckRow;
  8. use App\Admin\Extensions\MyDetailPage;
  9. use App\Admin\Extensions\OrderDetail;
  10. use App\Admin\Extensions\OrderDetailCopy;
  11. use App\Admin\Extensions\OrderPrint;
  12. use App\Admin\Extensions\OrderRefund;
  13. use App\Admin\Extensions\OrderStateHandle;
  14. use App\Admin\Repositories\ImsCjdcOrderMain;
  15. use App\Libs\SsdbClient;
  16. use App\Models\ImsCjdcMarket;
  17. use App\Models\LanzuStore;
  18. use Dcat\Admin\Admin;
  19. use Dcat\Admin\Form;
  20. use Dcat\Admin\Grid;
  21. use Dcat\Admin\Layout\Content;
  22. use Dcat\Admin\Show;
  23. use Dcat\Admin\Controllers\AdminController;
  24. use Dcat\Admin\Widgets\Lazy;
  25. use Dcat\Admin\Widgets\Modal;
  26. class ImsCjdcOrderMainController extends AdminController
  27. {
  28. /**
  29. * Make a grid builder.
  30. *
  31. * @return Grid
  32. */
  33. protected function grid()
  34. {
  35. return Grid::make(new ImsCjdcOrderMain(), function (Grid $grid) {
  36. //>>1.只展示线上订单打√
  37. //>>2.不同服务站只能看到自己的市场订单
  38. //>>3.订单不允许有添加,编辑,删除
  39. //>>4.订单状态变更√
  40. //>>5.打印功能
  41. //>6.退款
  42. $grid->tools(new ShowOrderStateHandle(2));
  43. $grid->tools(new ShowOrderStateHandle(3));
  44. $grid->tools(new ShowOrderStateHandle(311));
  45. $grid->tools(new ShowOrderStateHandle(8));
  46. $grid->tools(new ShowOrderStateHandle());
  47. $grid->paginate(10);//每页展示数据10条
  48. if (!(Admin::user()->isRole('market_service'))){
  49. $marketId = \Request::get('market_id');
  50. if ($marketId){
  51. $grid->model()->where('market_id',$marketId);
  52. }
  53. }else{
  54. $marketId =Auth::getMarket();
  55. $grid->model()->where('market_id',$marketId);
  56. }
  57. $grid->column('nick_name', '用户信息');
  58. $grid->order_num;
  59. $grid->state('订单状态')
  60. ->using(config('order.state'))
  61. ->label([1 => 'dark', 2 => 'danger', 3 => 'indigo', 4 => 'success',8=>'warning',311=>'#bd10e0']);
  62. $grid->money;
  63. $grid->column('market.name', '所属市场');
  64. $grid->pay_time('支付时间')->display(function ($time) {
  65. if ($time){
  66. return date('Y-m-d H:i:s',$time);
  67. }
  68. return '<span style="color: #ceccce">未支付</span>';
  69. });
  70. $grid->column('shipping_type', '配送方式')
  71. ->using(config('order.shipping_type'))
  72. ->label([1 => '#FF9900', 2 => '#99CCFF', 3 => '#CCCCCC']);
  73. $grid->created_at('下单时间')->display(function ($time) {
  74. return date('Y-m-d H:i:s',$time);
  75. });
  76. $grid->actions(function (Grid\Displayers\Actions $actions) use ($grid) {
  77. $state = $actions->row->state;
  78. $lastUrl = isset($_SERVER['QUERY_STRING'])?base64_encode($_SERVER['QUERY_STRING']):'';
  79. $actions->append(new OrderDetail($actions->row->id, $grid->model()->getCurrentPage(),$lastUrl, '<div type="button" class="btn btn-outline-primary btn-sm">详情</div>'));
  80. if ($state == 2) {
  81. $actions->append(new OrderStateHandle('<div type="button" class="btn btn-outline-danger btn-sm">接单</div>', 3));
  82. } elseif ($state == 311) {
  83. $actions->append(new OrderStateHandle('<div type="button" class="btn btn-outline-warning btn-sm">完成</div>', 4));
  84. $actions->append(new OrderPrint('<div type="button" class="btn btn-outline-dark btn-sm">打印</div>'));
  85. } elseif ($state == 3) {
  86. $actions->append(new OrderPrint('<div type="button" class="btn btn-outline-dark btn-sm">打印</div>'));
  87. if($actions->row->shipping_type == 3){
  88. $actions->append(new OrderStateHandle('<div type="button" class="btn btn-outline-warning btn-sm">完成</div>', 4));
  89. }else{
  90. $actions->append(new CheckRow($actions->row->id, $grid->model()->getCurrentPage(), '<div type="button" class="btn btn-outline-info btn-sm">自送</div>'));
  91. }
  92. } elseif ($state == 8) {
  93. $actions->append(new OrderStateHandle('<div type="button" class="btn btn-outline-secondary btn-sm">同意</div>', 9));
  94. $actions->append(new OrderRefund($actions->row->id, $grid->model()->getCurrentPage(), '<div type="button" class="btn btn-outline-secondary btn-sm">拒绝</div>'));
  95. }
  96. });
  97. $grid->filter(function (Grid\Filter $filter) {
  98. $filter->equal('order_num');
  99. if (!(Admin::user()->isRole('market_service'))){
  100. $filter->equal('market_id','所属市场')->select(ImsCjdcMarket::getMarket());
  101. }
  102. $filter->equal('store_id','店铺')->select(LanzuStore::getData(Auth::getMarket()));
  103. $filter->between('created_at','下单时间')->datetime();
  104. $filter->between('money','订单金额');
  105. $filter->equal('state','订单状态')->select(
  106. [1=>'待付款',4=>'已完成',6=>'已取消',9=>'已退款',10=>'退款拒绝']
  107. );
  108. $filter->disableResetButton();
  109. });
  110. $grid->disableViewButton();
  111. $grid->disableEditButton();
  112. $grid->disableDeleteButton();
  113. $grid->disableCreateButton();
  114. });
  115. }
  116. /**
  117. * Make a show builder.
  118. *
  119. * @param mixed $id
  120. *
  121. * @return Show
  122. */
  123. protected function detail($id)
  124. {
  125. return Show::make($id, new ImsCjdcOrderMain(), function (Show $show) {
  126. $show->id;
  127. $show->user_id;
  128. $show->order_num;
  129. $show->state;
  130. $show->time;
  131. $show->pay_time;
  132. $show->money;
  133. $show->tools(function (Show\Tools $tools) {
  134. $tools->append(new \App\Admin\Actions\Show\OrderDetail());
  135. });
  136. });
  137. }
  138. /**
  139. * Make a form builder.
  140. *
  141. * @return Form
  142. */
  143. protected function form()
  144. {
  145. return Form::make(new ImsCjdcOrderMain(), function (Form $form) {
  146. $form->display('id');
  147. $form->text('user_id');
  148. $form->text('order_num');
  149. $form->text('state');
  150. $form->text('time');
  151. $form->text('pay_time');
  152. $form->text('money');
  153. });
  154. }
  155. /**
  156. * 订单详情
  157. * @param Content $content
  158. * @return Content
  159. */
  160. public function orderDetail(Content $content)
  161. {
  162. $oid = request()->get('order_id');
  163. $page = request()->get('page');
  164. $lastUrl = base64_decode(request()->get('last_url'));
  165. // 实例化表单类并传递自定义参数
  166. $detail = MyDetailPage::make(['order_id' => $oid,'page'=>$page,'last_url'=>$lastUrl]);
  167. return $content->header("<a href='order?{$lastUrl}'><<返回</a>")
  168. ->breadcrumb(
  169. ['text' => '返回', 'url' => "order?page={$page}"],
  170. ['text' => '详情', 'url' => 'detail']
  171. )
  172. ->body(Lazy::make($detail));
  173. }
  174. public function orderGoodsRefund()
  175. {
  176. $uid = request()->get('user_id');
  177. $note = request()->get('note');
  178. $global_order_id = request()->get('global_order_id');
  179. $order_child_id = request()->get('order_child_id');
  180. $order_goods_id = request()->get('order_goods_id');
  181. $result = Rpc::onlineSingleRefund($uid, $note, $global_order_id, $order_child_id, $order_goods_id);
  182. return json_encode($result['result']);
  183. }
  184. /**
  185. * 地图路线规划
  186. * @param $m_lat
  187. * @param $m_lng
  188. * @param $u_lat
  189. * @param $u_lng
  190. * @param $type
  191. * @return false|string
  192. */
  193. public function mapRoute()
  194. {
  195. $params = request()->input();
  196. $m_lat = $params['m_lat'];
  197. $m_lng = $params['m_lng'];
  198. $u_lat = $params['u_lat'];
  199. $u_lng = $params['u_lng'];
  200. $type = $params['type'];
  201. return Map::routeInfo($m_lat,$m_lng,$u_lat,$u_lng,$type);
  202. }
  203. /**
  204. * 获取骑手定位
  205. * @return false|string
  206. */
  207. public function getHorsemanPosition()
  208. {
  209. $ssdb = SsdbClient::client(env('SSDB_HOST'), env('SSDB_PORT'));
  210. $hid = request()->get('horseman_id');
  211. $coordinate= $ssdb->get("horseman_coordinate_{$hid}");
  212. $data = [];
  213. $code = 200;
  214. if ($coordinate){
  215. list($data['lng'],$data['lat']) = explode(',',$coordinate);
  216. }else{
  217. $code = 0;
  218. }
  219. return json_encode(['code'=>$code,'data'=>$data]);
  220. }
  221. }