feat: 修改订单控制器与列表,增强错误处理与功能,优化代码结构

This commit is contained in:
mkm 2024-08-10 09:18:57 +08:00
parent 8b7e043dc9
commit 09d157d81a
2 changed files with 20 additions and 12 deletions

View File

@ -10,6 +10,7 @@ use app\admin\logic\store_order\StoreOrderLogic;
use app\admin\validate\store_order\StoreOrderValidate; use app\admin\validate\store_order\StoreOrderValidate;
use app\common\enum\PayEnum; use app\common\enum\PayEnum;
use app\common\logic\PayNotifyLogic; use app\common\logic\PayNotifyLogic;
use app\common\model\delivery_service\DeliveryService;
use app\common\model\store_order\StoreOrder; use app\common\model\store_order\StoreOrder;
@ -112,12 +113,12 @@ class StoreOrderController extends BaseAdminController
public function refund() public function refund()
{ {
$params = (new StoreOrderValidate())->goCheck('refund'); $params = (new StoreOrderValidate())->goCheck('refund');
$detail = StoreOrder::where('order_id',$params['order_id'])->findOrEmpty(); $detail = StoreOrder::where('order_id', $params['order_id'])->findOrEmpty();
if(empty($detail)){ if (empty($detail)) {
return $this->fail('无该订单请检查'); return $this->fail('无该订单请检查');
} }
$res=StoreOrderLogic::refund($detail,$params); $res = StoreOrderLogic::refund($detail, $params);
if($res==false){ if ($res == false) {
return $this->fail('退款失败'); return $this->fail('退款失败');
} }
return $this->success('退款成功'); return $this->success('退款成功');
@ -126,14 +127,18 @@ class StoreOrderController extends BaseAdminController
/** /**
* 设置配送员 * 设置配送员
*/ */
public function set_delivery(){ public function set_delivery()
$id=$this->request->post('id'); {
$delivery_uid=$this->request->post('delivery_uid'); $id = $this->request->post('id');
$res=StoreOrder::where('id',$id)->update(['delivery_uid'=>$delivery_uid]); $delivery_uid = $this->request->post('delivery_uid');
if($res){ $find = DeliveryService::where('id', $delivery_uid)->find();
if(empty($find)){
return $this->fail('配送员不存在');
}
$res = StoreOrder::where('id', $id)->update(['delivery_uid' => $delivery_uid,'delivery_name'=>$find['nickname'],'delivery_id'=>$find['phone']]);
if ($res) {
return $this->success('设置成功'); return $this->success('设置成功');
} }
return $this->success('设置失败'); return $this->success('设置失败');
} }
} }

View File

@ -47,6 +47,9 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
*/ */
public function lists(): array public function lists(): array
{ {
if($this->request->get('is_delivery')>=1){
$this->searchWhere[]=['delivery_uid','>',0];
}
return StoreOrder::with(['staff','store'])->where($this->searchWhere) return StoreOrder::with(['staff','store'])->where($this->searchWhere)
->when(!empty($this->request->adminInfo['store_id']), function ($query) { ->when(!empty($this->request->adminInfo['store_id']), function ($query) {
$query->where('store_id', $this->request->adminInfo['store_id']); $query->where('store_id', $this->request->adminInfo['store_id']);
@ -59,7 +62,7 @@ class StoreOrderLists extends BaseAdminDataLists implements ListsSearchInterface
$query->whereIn('status', $status); $query->whereIn('status', $status);
} }
}) })
->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time']) ->field(['id', 'store_id', 'staff_id', 'order_id', 'paid', 'pay_price', 'pay_time', 'pay_type', 'status', 'uid','refund_status','create_time','delivery_name','delivery_id'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function ($item) { ->select()->each(function ($item) {