Browse Source

订单列表增加退款申请按钮

master
lanzu_qinsheng 5 years ago
parent
commit
c2107be566
  1. 42
      app/Admin/Actions/Tools/ShowOrderStateHandle.php
  2. 6
      app/Admin/Controllers/ImsCjdcOrderMainController.php
  3. 4
      app/Admin/Forms/RefundNote.php
  4. 50
      app/Models/ImsCjdcOrderMain.php

42
app/Admin/Actions/Tools/ShowOrderStateHandle.php

@ -0,0 +1,42 @@
<?php
namespace App\Admin\Actions\Tools;
use App\Admin\Common\Auth;
use App\Models\ImsCjdcOrderMain;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid\Tools\AbstractTool;
class ShowOrderStateHandle extends AbstractTool
{
protected $state;
public function __construct($state=null)
{
$this->state = $state;
parent::__construct($title=null);
}
protected function script()
{
$url = "order?state=".$this->state;
return <<<JS
$(".order_state_{$this->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 "<a class=\"btn btn-primary order_state_{$this->state}\">{$title}</a>";
}
}

6
app/Admin/Controllers/ImsCjdcOrderMainController.php

@ -2,6 +2,7 @@
namespace App\Admin\Controllers; namespace App\Admin\Controllers;
use App\Admin\Actions\Tools\ShowOrderStateHandle;
use App\Admin\Common\Auth; use App\Admin\Common\Auth;
use App\Admin\Common\Rpc; use App\Admin\Common\Rpc;
use App\Admin\Extensions\CheckRow; use App\Admin\Extensions\CheckRow;
@ -38,6 +39,8 @@ class ImsCjdcOrderMainController extends AdminController
//>>4.订单状态变更√ //>>4.订单状态变更√
//>>5.打印功能 //>>5.打印功能
//>6.退款 //>6.退款
$grid->tools(new ShowOrderStateHandle(2));
$grid->tools(new ShowOrderStateHandle(8));
$grid->paginate(10);//每页展示数据10条 $grid->paginate(10);//每页展示数据10条
//$grid->id; //$grid->id;
//$grid->user_id('用户信息'); //$grid->user_id('用户信息');
@ -99,6 +102,9 @@ class ImsCjdcOrderMainController extends AdminController
} }
$filter->between('created_at','下单时间')->datetime(); $filter->between('created_at','下单时间')->datetime();
$filter->between('money','订单金额'); $filter->between('money','订单金额');
$filter->equal('state','订单状态')->select(
[1=>'待付款',2=>'待接单',4=>'已经成',6=>'已经取消',8=>'退款中',9=>'已退款',10=>'退款拒绝']
);
}); });
$grid->disableViewButton(); $grid->disableViewButton();

4
app/Admin/Forms/RefundNote.php

@ -41,8 +41,8 @@ class RefundNote extends Form
public function form() public function form()
{ {
$this->textarea('refuse_refund_note', '原因')->placeholder('请填写拒绝退款的理由,字数不得超过50个字')->required(); $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');
} }
/** /**

50
app/Models/ImsCjdcOrderMain.php

@ -10,65 +10,81 @@ use Illuminate\Support\Facades\DB;
class ImsCjdcOrderMain extends Model class ImsCjdcOrderMain extends Model
{ {
use HasDateTimeFormatter;
use HasDateTimeFormatter;
//protected $table = 'ims_cjdc_order_main'; //protected $table = 'ims_cjdc_order_main';
protected $table = 'lanzu_order_main'; protected $table = 'lanzu_order_main';
public $timestamps = false; public $timestamps = false;
public function imsCjdcUser() public function imsCjdcUser()
{ {
return $this->hasOne('\App\Models\ImsCjdcUser','id','user_id');
return $this->hasOne('\App\Models\ImsCjdcUser', 'id', 'user_id');
} }
public function market() 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 //订单状态 * @param $state //订单状态
*/ */
public function modifyState($oid,$state)
public function modifyState($oid, $state)
{ {
$where = []; $where = [];
$where['state'] = $state; $where['state'] = $state;
$where['updated_at'] = time(); $where['updated_at'] = time();
if ($state==3) {
if ($state == 3) {
$where['receive_time'] = time(); $where['receive_time'] = time();
}elseif ($state==4){
} elseif ($state == 4) {
$where['complete_time'] = time(); $where['complete_time'] = time();
}elseif ($state==6){
} elseif ($state == 6) {
$where['cancel_time'] = time(); $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) 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['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['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['pay_type'] = config('order.pay_type')[$order['pay_type']];
$order['shipping_type'] = config('order.shipping_type')[$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']);
//获取市场经纬度 //获取市场经纬度
//$market = LanzuMarket::where('id',$order['market_id'])->first()->toArray(); //$market = LanzuMarket::where('id',$order['market_id'])->first()->toArray();
//$order['distance'] = Rpc::getDistance($market['lng'],$market['lat'],$order['lng'],$order['lat'])['result']; //$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; 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;
}
} }
Loading…
Cancel
Save