123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace App\Community\Actions\Nurse;
- use App\Models\Order;
- use App\Models\User;
- use Encore\Admin\Actions\RowAction;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- class OrderCance extends RowAction
- {
- public $name = '取消订单';
- public function handle(Model $model)
- {
- $id = $this->row->order_id;
- $order = Order::where(['id'=>$id])->with('orderUser')->first();
- $sn = $order->order_sn;
- if(empty($order->orderUser) || empty($order->orderUser->openid) ) return true;
- $openid = $order->orderUser->openid;
- //$openid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
- $time = $this->row->created_at;
- $price = (intval($this->row->price) / 100).'元';
- DB::beginTransaction();
- try {
- //退还余额
- $res = Order::orderCancel($id,'社区取消');
- $msg = [
- $openid,'/pages/index/index','您有一个订单已取消',$sn,'儿保订单',$price,$time,'社区取消','如有疑问请联系客服'
- ];
- $ret = send_wechat_message(9,$msg,'','');
- DB::commit();
- } catch ( \Exception $e){
- dump($e->getMessage());
- DB::rollBack();
- return $this->response()->error('操作失败!');
- }
- if($res){
- return $this->response()->success('操作成功!')->refresh();
- }
- return $this->response()->error('操作失败!');
- }
- }
|