diff --git a/app/Admin/Actions/Tools/ShowOrderStateHandle.php b/app/Admin/Actions/Tools/ShowOrderStateHandle.php new file mode 100644 index 0000000..8c3e38b --- /dev/null +++ b/app/Admin/Actions/Tools/ShowOrderStateHandle.php @@ -0,0 +1,42 @@ +state = $state; + parent::__construct($title=null); + } + + protected function script() + { + $url = "order?state=".$this->state; + return <<state}").on('click',function () { + window.location.href = "{$url}" +}); +JS; + } + + public function render() + { + $title = ''; + $count = ImsCjdcOrderMain::getOrderStateCount($this->state,Auth::getMarket()); + if ($this->state==8){ + $title = "退款申请(".$count.")"; + }elseif ($this->state==2){ + $title = "待接单(".$count.")"; + } + Admin::script($this->script()); + return "state}\">{$title}"; + } + + +} diff --git a/app/Admin/Controllers/ImsCjdcOrderMainController.php b/app/Admin/Controllers/ImsCjdcOrderMainController.php index d7d0121..778d53c 100644 --- a/app/Admin/Controllers/ImsCjdcOrderMainController.php +++ b/app/Admin/Controllers/ImsCjdcOrderMainController.php @@ -2,6 +2,7 @@ namespace App\Admin\Controllers; +use App\Admin\Actions\Tools\ShowOrderStateHandle; use App\Admin\Common\Auth; use App\Admin\Common\Rpc; use App\Admin\Extensions\CheckRow; @@ -38,6 +39,8 @@ class ImsCjdcOrderMainController extends AdminController //>>4.订单状态变更√ //>>5.打印功能 //>6.退款 + $grid->tools(new ShowOrderStateHandle(2)); + $grid->tools(new ShowOrderStateHandle(8)); $grid->paginate(10);//每页展示数据10条 //$grid->id; //$grid->user_id('用户信息'); @@ -101,6 +104,9 @@ class ImsCjdcOrderMainController extends AdminController } $filter->between('created_at','下单时间')->datetime(); $filter->between('money','订单金额'); + $filter->equal('state','订单状态')->select( + [1=>'待付款',2=>'待接单',4=>'已完成',6=>'已取消',8=>'退款中',9=>'已退款',10=>'退款拒绝'] + ); }); $grid->disableViewButton(); diff --git a/app/Admin/Forms/RefundNote.php b/app/Admin/Forms/RefundNote.php index 8a99b7b..b8f4abb 100644 --- a/app/Admin/Forms/RefundNote.php +++ b/app/Admin/Forms/RefundNote.php @@ -41,8 +41,8 @@ class RefundNote extends Form public function form() { $this->textarea('refuse_refund_note', '原因')->placeholder('请填写拒绝退款的理由,字数不得超过50个字')->required(); - $this->hidden('order_id')->value($this->data['order_id']); - $this->hidden('current_page')->value($this->data['current_page']); + $this->hidden('order_id'); + $this->hidden('current_page'); } /** diff --git a/app/Models/ImsCjdcOrderMain.php b/app/Models/ImsCjdcOrderMain.php index 60e3915..891ba54 100644 --- a/app/Models/ImsCjdcOrderMain.php +++ b/app/Models/ImsCjdcOrderMain.php @@ -52,50 +52,50 @@ class ImsCjdcOrderMain extends Model public function imsCjdcUser() { - return $this->hasOne('\App\Models\ImsCjdcUser','id','user_id'); + return $this->hasOne('\App\Models\ImsCjdcUser', 'id', 'user_id'); } public function market() { - return $this->hasOne('\App\Models\ImsCjdcMarket','id','market_id'); + return $this->hasOne('\App\Models\ImsCjdcMarket', 'id', 'market_id'); } /** * 变更订单状态, - * @param $oid //主订单id + * @param $oid //主订单id * @param $state //订单状态 */ - public function modifyState($oid,$state) + public function modifyState($oid, $state) { $where = []; $where['state'] = $state; $where['updated_at'] = time(); - if ($state==3) { + if ($state == 3) { $where['receive_time'] = time(); - }elseif ($state==4){ + } elseif ($state == 4) { $where['complete_time'] = time(); - }elseif ($state==6){ + } elseif ($state == 6) { $where['cancel_time'] = time(); } - return self::where('id',$oid)->update($where); + return self::where('id', $oid)->update($where); } - public function updateShippingType($oid,$type) + public function updateShippingType($oid, $type) { - return self::where('id',$oid)->update(['shipping_type'=>$type]); + return self::where('id', $oid)->update(['shipping_type' => $type]); } public static function getOrderData($oid) { - $order = ImsCjdcOrderMain::where('id', $oid)->first()->toArray(); + $order = ImsCjdcOrderMain::where('id', $oid)->first()->toArray(); $order['created_at'] = date('Y-m-d H:i:s', $order['created_at']); $order['updated_at'] = $order['updated_at'] ? date('Y-m-d H:i:s', $order['updated_at']) : null; $order['pay_type'] = config('order.pay_type')[$order['pay_type']]; $order['shipping_type_num'] = $order['shipping_type']; $order['shipping_type'] = config('order.shipping_type')[$order['shipping_type']]; - $order['horseman_name'] = $order['shipping_name']??LanzuServiceHorseman::getName($order['horseman_id']); + $order['horseman_name'] = $order['shipping_name'] ?? LanzuServiceHorseman::getName($order['horseman_id']); // 获取市场 $marketId = $order['market_id']?$order['market_id']:0; @@ -105,11 +105,26 @@ class ImsCjdcOrderMain extends Model //获取市场经纬度 //$market = LanzuMarket::where('id',$order['market_id'])->first()->toArray(); //$order['distance'] = Rpc::getDistance($market['lng'],$market['lat'],$order['lng'],$order['lat'])['result']; - if ($order['delivery_distance']>1000){ - $order['delivery_distance']= number_format(($order['delivery_distance']/1000), 1) .'km'; - }else{ - $order['delivery_distance'].= '米'; + if ($order['delivery_distance'] > 1000) { + $order['delivery_distance'] = number_format(($order['delivery_distance'] / 1000), 1) . 'km'; + } else { + $order['delivery_distance'] .= '米'; } return $order; } + + public static function getOrderStateCount($state, $marketId = null) + { + if ($marketId) { + $count = self::where('state', $state) + ->where('type', 1) + ->where('market_id',$marketId) + ->count(); + }else{ + $count = self::where('state', $state) + ->where('type', 1) + ->count(); + } + return $count; + } }