UserOrder.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. <?php
  2. namespace app\common\model;
  3. use app\service\pay_user\PayUser;
  4. use think\Db;
  5. use think\db\Query;
  6. use think\Model;
  7. use think\model\Collection;
  8. use traits\model\SoftDelete;
  9. /**
  10. *@property array send_detail 运送详情
  11. *@property float cal_refund 退款手续费
  12. *@property float refund_money 退款金额
  13. *@property Collection currentSenderOrder
  14. *@property float settle_amount
  15. *@property array senders
  16. *@property array settle_info
  17. *@property float profit
  18. *@property boolean is_same_user
  19. *@property User user
  20. *@method Query|self expired()
  21. *@method Query|self show()
  22. *@method Query|self service()()
  23. *@method Query|self waitGet()
  24. *@method Query|self running($from='')
  25. *@method Query|self success()
  26. *@method Query|self settled()
  27. *@method Query|self canceled()
  28. *@method Query|self completed()
  29. *@method Query|self caled()
  30. *@method Query|self profit()
  31. *@method Query|self over()
  32. *@method Query|self turnover($date='today')
  33. */
  34. class UserOrder extends Model
  35. {
  36. //use SoftDelete;
  37. protected $hidden=[
  38. 'status_bak',
  39. 'deleted_at',
  40. ];
  41. protected $autoWriteTimestamp=true;
  42. protected $createTime = 'created_at';
  43. protected $updateTime = 'updated_at';
  44. protected $deleteTime='deleted_at';
  45. protected $type=[
  46. 'has_cage'=>'boolean',
  47. 'from_addr'=>'json',
  48. 'to_addr'=>'json',
  49. 'refund_images'=>'array',
  50. 'created_at'=>'datetime',
  51. 'pay_time'=>'datetime',
  52. ];
  53. const FREIGHT_FAST='fast';#快车
  54. const FREIGHT_AIR='air';#空运
  55. const FREIGHT_SPECIAL='special';#专车
  56. public static $freights=[
  57. self::FREIGHT_FAST=>'快车',
  58. self::FREIGHT_AIR=>'空运',
  59. self::FREIGHT_SPECIAL=>'专车',
  60. ];
  61. const STATUS_WAIT_PAY=0;
  62. const STATUS_WAIT_GET=1;
  63. const STATUS_GETTING=10;
  64. const STATUS_SENDING=20;
  65. const STATUS_GIVING=30;
  66. const STATUS_GIVED=40;
  67. const STATUS_COMPLETE=50;
  68. const STATUS_WAIT_SET=55;
  69. const STATUS_SET=60;
  70. const STATUS_SET_REJECT=65;
  71. const STATUS_REFUND=70;
  72. const STATUS_CANCEL=80;
  73. public static $statusList=[
  74. self::STATUS_WAIT_PAY=>'待支付',
  75. self::STATUS_WAIT_GET=>'待接单',
  76. self::STATUS_GETTING=>'已接单,取宠中',
  77. self::STATUS_SENDING=>'已取宠,运输中',
  78. self::STATUS_GIVING=>'送宠中',
  79. self::STATUS_GIVED=>'送宠完成,待用户确认',
  80. self::STATUS_COMPLETE=>'已完成,待提交结算信息',
  81. self::STATUS_WAIT_SET=>'已提交结算信息,待后台结算',
  82. self::STATUS_SET=>'已结算',
  83. self::STATUS_SET_REJECT=>'已拒绝结算',
  84. self::STATUS_REFUND=>'退款处理中',
  85. self::STATUS_CANCEL=>'已取消',
  86. ];
  87. const REFUND_STATUS_DEFAULT=0;
  88. const REFUND_STATUS_PASS=1;
  89. const REFUND_STATUS_REJECT=2;
  90. public static $refundStatus=[
  91. self::REFUND_STATUS_DEFAULT=>'审核中',
  92. self::REFUND_STATUS_PASS=>'审核通过',
  93. self::REFUND_STATUS_REJECT=>'驳回',
  94. ];
  95. protected $append=[
  96. 'protect_valid',
  97. ];
  98. public function user(){
  99. return $this->belongsTo(User::class);
  100. }
  101. public function log(){
  102. return $this->hasMany(UserOrderLog::class,'order_id')/*->order('id','desc')*/;
  103. }
  104. public static function payed($params){
  105. $id=$params['id'];
  106. $order=self::find($id);
  107. $order['pay_time']=time();
  108. $order['status']=self::STATUS_WAIT_GET;
  109. $order->save();
  110. }
  111. public function setImagesAttr($v){
  112. if(!$v){
  113. $v=[];
  114. }
  115. return json_encode($v);
  116. }
  117. public function getImagesAttr($v){
  118. return array_filter(json_decode($v));
  119. }
  120. /**
  121. * 取消
  122. *user.type 1未支付2驳回3退款
  123. *user.reason
  124. */
  125. const CT_NOT_PAY=1;
  126. const CT_REJECT=2;
  127. const CT_REFUND=3;
  128. public function cancel($type=self::CT_NOT_PAY,$force=false){
  129. if($this['status']!==self::STATUS_WAIT_PAY && !$force){
  130. throw_user('非待付款订单无法取消');
  131. }
  132. $this['status']=self::STATUS_CANCEL;
  133. $this['cancel_at']=time();
  134. $this['cancel_type']=$type;
  135. $this->save();
  136. if($this['coupon_id']){
  137. UserCoupon::setUse($this['coupon_id'],0);
  138. }
  139. }
  140. public function pay(){
  141. if($this['status']!=self::STATUS_WAIT_PAY){
  142. throw_user('状态有误');
  143. }
  144. if($this['expired_at']<time()){
  145. $this->cancel();
  146. throw_user('该订单已超时');
  147. }
  148. if($this['pay_type']==1){
  149. $params='';
  150. $this->user->money(bcsub(0,$this['real_amount'],2),$this['user_id'],MoneyLog::TYPE_ORDER_PAY,"订单[{$this['no']}]付款");
  151. self::payed(['id'=>$this['id']]);
  152. }else {
  153. $params = Payment::pay($this->user, $this['real_amount'], self::class, 'payed', ['id' => $this['id']]);
  154. }
  155. return $params;
  156. }
  157. public function complete(){
  158. $this->refunding();
  159. if($this['status']!=self::STATUS_GIVED){
  160. throw_user('非已送达状态无法确认完成');
  161. }
  162. $this['status']=self::STATUS_COMPLETE;
  163. $this['completed_at']=time();
  164. if(!$this->save()){
  165. throw_user('保存状态失败');
  166. }
  167. }
  168. public function refund($reason,$images){
  169. if(!in_array($this['status'],[self::STATUS_WAIT_GET,self::STATUS_GETTING,self::STATUS_SENDING])){
  170. throw_user('当前无法申请退款');
  171. }
  172. $this['refund_reason']=$reason;
  173. $this['refund_apply_at']=time();
  174. $this['refund_amount']=$this->refund_money;
  175. $this['refund_images']=$images;
  176. $this['refund_status']=self::REFUND_STATUS_DEFAULT;
  177. $this['status_bak']=$this['status'];
  178. $this['status']=self::STATUS_REFUND;
  179. if(!$this->save()){
  180. throw_user('保存失败');
  181. }
  182. }
  183. public function refundCancel(){
  184. if(!in_array($this['refund_status'],[self::REFUND_STATUS_DEFAULT])){
  185. throw_user('当前无法取消申请退款');
  186. }
  187. $this['refund_status']=-1;
  188. $this['status']=$this['status_bak'];
  189. if(!$this->save()){
  190. throw_user('保存失败');
  191. }
  192. }
  193. public function refunding(bool $throw=true){
  194. $is=in_array($this['refund_status'],[self::REFUND_STATUS_DEFAULT,self::REFUND_STATUS_PASS]);
  195. if($throw && $is){
  196. throw_user('当前正在申请退款或已退款,您无法操作');
  197. }
  198. return $is;
  199. }
  200. /**
  201. *处理退款申请
  202. * @status 1同意2拒绝
  203. */
  204. public function dealRefund($data){
  205. if($data['status']==1){
  206. $this['refund_status']=self::REFUND_STATUS_PASS;
  207. $this['refund_at']=time();
  208. PayUser::setType($this['pay_type']);
  209. PayUser::getClass()->payment($this['refund_amount'],$this['user'],MoneyLog::TYPE_REFUND,"订单退款",['order_id'=>$this['id']]);
  210. $this->cancel(self::CT_REFUND,true);
  211. }elseif($data['status']==2){
  212. $this['refund_status']=self::REFUND_STATUS_REJECT;
  213. $this['status']=$this['status_bak'];
  214. }
  215. $this->save();
  216. }
  217. /**
  218. *处理结算申请
  219. * @status 1同意2拒绝
  220. */
  221. public function dealSettle($data){
  222. if($this['status']!=self::STATUS_WAIT_SET){
  223. throw_user(sprintf('非待结算订单无法结算[%s]',self::$statusList[$this['status']]));
  224. }
  225. if($data['status']==1){
  226. $this['status']=self::STATUS_SET;
  227. foreach ($this->currentSenderOrder as $senderOrder){
  228. if(is_null($senderOrder['fee_total'])){
  229. throw_user('有配送员尚未申请结算,请稍后再试');
  230. }
  231. PayUser::getClass()->payment($senderOrder['fee_total'],$senderOrder['user'],MoneyLog::TYPE_SETTLE,"订单[{$this['no']}]结算",['order_id'=>$this['id']]);
  232. }
  233. #加一个盈利记录
  234. User::money($this->profit,0,MoneyLog::TYPE_PROFIT,"订单[{$this['no']}]盈利",['order_id'=>$this['id']],false);
  235. }elseif($data['status']==2){
  236. $this['status']=self::STATUS_SET_REJECT;
  237. }
  238. $this['settled_at']=time();
  239. if(!$this->save()){
  240. throw_user('保存失败');
  241. }
  242. }
  243. public function getCalRefundAttr($v,$data){
  244. if($this['freight']==self::FREIGHT_AIR){
  245. $fee=bcdiv(config('site.order_refund_air'),100,4);
  246. }else{
  247. $fee=bcdiv(config('site.order_refund_land'),100,4);
  248. }
  249. $amount=bcmul($this['real_amount'],$fee);
  250. return $amount;
  251. }
  252. public function getRefundMoneyAttr($v,$data){
  253. return bcsub($this['real_amount'],$this->cal_refund);
  254. }
  255. public function getSendDetailAttr(){
  256. $log=$this->log()->select();
  257. $res['addr']=$this['to_addr']['address'];
  258. $res['log']=$log;
  259. return $res;
  260. }
  261. public function remove(){
  262. if(!in_array($this['status'],[self::STATUS_CANCEL,self::STATUS_SET,self::STATUS_SET_REJECT])){
  263. throw_user('非已取消或完成订单无法删除');
  264. }
  265. if($this['user_deleted_at']){
  266. throw_user('该订单已删除');
  267. }
  268. $this['user_deleted_at']=time();
  269. $this->save();
  270. }
  271. public function submit($data){
  272. $this['status']=self::STATUS_WAIT_PAY;
  273. $res=$this->allowField(true)->save($data);
  274. if(!$res){
  275. throw_user('保存失败');
  276. }
  277. if($this['coupon_id']){
  278. UserCoupon::setUse($this['coupon_id']);
  279. }
  280. }
  281. /** 待接单 */
  282. public static function wait(User $user){
  283. $q=self::alias('user_order');
  284. $city=$user->area()->column('name');
  285. if(empty($city)){
  286. $q->where('user_order.id',0);
  287. return $q;
  288. }
  289. $q
  290. ->join('sender_order b','user_order.id=b.user_order_id and b.now=1','LEFT')
  291. ->whereIn('user_order.from_city|user_order.to_city',$city)
  292. ->whereBetween('user_order.status',[self::STATUS_WAIT_GET,self::STATUS_GIVING])
  293. ->whereNotExists("select user_id from sender_order where user_order_id=user_order.id and user_id={$user['id']}")
  294. ->group('user_order.id')
  295. ->having('COUNT(b.id)<2')
  296. ->order('user_order.id','desc');
  297. return $q;
  298. }
  299. public function getProtectValidAttr($v,$d){
  300. if(!isset($this['status'])){
  301. return false;
  302. }
  303. return $this['status']>=self::STATUS_WAIT_GET && $this['status']<=self::STATUS_GIVED;
  304. }
  305. public function senderOrder(){
  306. return $this->hasMany(SenderOrder::class);
  307. }
  308. /** 当前的配送员订单 */
  309. public function currentSenderOrder($user_id=null){
  310. $q=$this->senderOrder()->where('now',1);
  311. if($user_id){
  312. $q->where('user_id',$user_id);
  313. }
  314. return $q;
  315. }
  316. /** 是否能接单 */
  317. public function checkGet(User $user){
  318. if(count($this->currentSenderOrder)>1){
  319. throw_user('订单已被接单,您暂时无法接单(1)');
  320. }
  321. $type=$user->getSendType($this);
  322. /*if($user->isSendGet($type) && $this['status'] != self::STATUS_WAIT_GET) {
  323. throw_user("订单已被接单,您暂时无法接单(2)");
  324. }*/
  325. return $type;
  326. }
  327. /** 接单 */
  328. public function accept(User $user){
  329. $type=$this->checkGet($user);
  330. if($this['status']==self::STATUS_WAIT_GET) {
  331. $this['status'] = self::STATUS_GETTING;
  332. }
  333. #取送都是自己,取送订单创建
  334. if($user->isSendAll($type)){
  335. $time=time();
  336. $get=$this->senderOrder()->save([
  337. 'user_id'=>$user['id'],
  338. 'status' =>$this['status'],
  339. 'type' =>1,
  340. 'now' =>1,
  341. 'get_at' =>$time,
  342. ]);
  343. if(!$get){
  344. throw_user('保存取宠订单失败');
  345. }
  346. $sender=$this->senderOrder()->save([
  347. 'user_id'=>$user['id'],
  348. 'status' =>$this['status'],
  349. 'type' =>2,
  350. 'now' =>1,
  351. 'get_at' =>$time,
  352. ]);
  353. if(!$sender){
  354. throw_user('保存送宠订单失败');
  355. }
  356. }else{
  357. $sender_order=$this->senderOrder()->save([
  358. 'user_id'=>$user['id'],
  359. 'status' =>$this['status'],
  360. 'type' =>$type,
  361. 'now' =>1,
  362. 'get_at' =>time(),
  363. ]);
  364. if(!$sender_order){
  365. throw_user('保存配送订单失败');
  366. }
  367. }
  368. if(!$this['get_at']){
  369. $this['get_at']=time();
  370. }
  371. $this->save();
  372. }
  373. /** 更新状态 */
  374. public function updateStatus($status,User $user){
  375. if(!$status){
  376. return;
  377. }
  378. $this->refunding();
  379. $senderS=[
  380. self::STATUS_GETTING=>self::STATUS_SENDING,
  381. self::STATUS_SENDING=>self::STATUS_GIVING,
  382. ];
  383. $recS=[
  384. self::STATUS_GIVING=>self::STATUS_GIVED,
  385. ];
  386. $arr=$senderS+$recS;
  387. if($this['status']!=$status){
  388. throw_user('状态'.self::$statusList[$this['status']].'有误');
  389. }
  390. if(!$this->is_same_user) {
  391. $type = $user->getSendType($this);
  392. if ($user->isSendGet($type) && !isset($senderS[$status])) {
  393. throw_user('您是取宠人,无法更新状态' . self::$statusList[$status]);
  394. } elseif ($user->isSendSend($type) && !isset($recS[$status])) {
  395. throw_user('您是送宠人,无法更新状态' . self::$statusList[$status]);
  396. }
  397. }
  398. $this['status']=$arr[$status];
  399. if(!$this->save()){
  400. throw_user('更新失败');
  401. }
  402. return $this['status'];
  403. }
  404. /** 进行中的订单 */
  405. public function scopeRunning(Query $query,$from=''){
  406. $status=[];
  407. if($from=='user'){
  408. $status=[
  409. self::STATUS_WAIT_GET,
  410. ];
  411. }
  412. $query
  413. ->show()
  414. ->whereIn('status',array_merge($status,[
  415. self::STATUS_GETTING,
  416. self::STATUS_SENDING,
  417. self::STATUS_GIVING,
  418. self::STATUS_GIVED,
  419. self::STATUS_REFUND,
  420. ]));
  421. }
  422. /** 计算收益 */
  423. public static function calcProfit($date=null){
  424. $profit=Db::query($sql=UserOrder::withTrashed()->profit($date)->buildSql());
  425. return bcadd(array_sum(array_column($profit,'profit')),0);
  426. }
  427. /** 结算金额 */
  428. public function getSettleAmountAttr($v,$data){
  429. $sender_order=$this->currentSenderOrder;
  430. $amount=0;
  431. foreach ($sender_order as $order){
  432. $amount=bcadd($amount,$order['fee_total']);
  433. }
  434. return $amount;
  435. }
  436. /** 配送员 */
  437. public function getSendersAttr($v,$data){
  438. $sender_order=$this->currentSenderOrder;
  439. foreach ($sender_order as $item){
  440. $item->append(['user']);
  441. }
  442. return array_column($sender_order->toArray(),null);
  443. }
  444. /** 结算总的金额 */
  445. public function getSettleInfoAttr($v,$data){
  446. $arr=$this->senders;
  447. $total=[
  448. 'fee_total'=>0
  449. ];
  450. foreach ($arr as $item){
  451. for ($i=1;$i<=6;$i++) {
  452. $total["fee_$i"] = bcadd($total["fee_$i"]??0,$item["fee_$i"]);
  453. }
  454. $total['fee_total']=bcadd($total['fee_total']??0,$item['fee_total']);
  455. }
  456. return $total;
  457. }
  458. /** 盈利总的金额 */
  459. public function getProfitAttr($v,$data){
  460. return bcsub($this['real_amount'],$this->settle_info['fee_total']);
  461. }
  462. /** 是否相同接单人 */
  463. public function getIsSameUserAttr(){
  464. return $this->currentSenderOrder->count()==2 && count(array_unique($this->currentSenderOrder->column('user_id')))==1;
  465. }
  466. /** init */
  467. protected static function init()
  468. {
  469. self::beforeInsert(function (self $order){
  470. $order['no']=order_no();
  471. $order['expired_at']=strtotime("+10minutes");
  472. });
  473. self::afterInsert(function (self $order){
  474. /* if(!$order->user->address()->exists($order['from_addr'])->find()) {
  475. $addr=$order['from_addr'];
  476. $addr['user_id']=$order->user_id;
  477. (new UserAddress())->allowField(true)->save($addr);
  478. }*/
  479. });
  480. self::afterUpdate(function (self $order){
  481. #更新配送订单状态
  482. $data=$order->getChangedData();
  483. if(isset($data['status'])){
  484. $order->senderOrder()->update(['status'=>$data['status']]);
  485. }
  486. });
  487. }
  488. /** scope */
  489. /**
  490. * 待结算
  491. * @param Query $query
  492. */
  493. public function scopeSettle(Query $query){
  494. $query->where('status',self::STATUS_WAIT_SET);
  495. }
  496. /**
  497. * 待处理退款
  498. * @param Query $query
  499. */
  500. public function scopeWaitRefund(Query $query){
  501. $query->where('status',self::STATUS_REFUND);
  502. }
  503. /**
  504. * 售后
  505. * @param static $query
  506. */
  507. public function scopeService(Query $query){
  508. $query->show()->where('refund_status','>',-1);
  509. }
  510. /**
  511. * 总营业额
  512. * @param Query $query
  513. * @param null|array $date
  514. */
  515. public function scopeTurnover(Query $query,$date='today'){
  516. $query
  517. ->whereBetween(($table=$this->getTable()).'.status', [self::STATUS_WAIT_GET, self::STATUS_SET]);
  518. if($date=='today') {
  519. $query->whereTime($table.'.created_at', $date);
  520. }elseif(is_array($date)){
  521. list($type,$time)=$date;
  522. if($type=='day'){
  523. $query->whereBetween($table.'.created_at',[strtotime($time),strtotime("+1day",strtotime($time))]);
  524. }elseif ($type=='month'){
  525. if (substr_count($time,'-')==1){
  526. $time="$time-01 00:00:00";
  527. }
  528. $query->whereBetween($table.'.created_at',[strtotime($time),strtotime("+1month",strtotime($time))]);
  529. }elseif ($type=='year'){
  530. $query->whereBetween($table.'.created_at',[strtotime("$time-01-01"),strtotime(($time+1).'-01-01')]);
  531. }
  532. }
  533. }
  534. /**
  535. * 盈利统计
  536. * @param null $date
  537. * @param bool $detail
  538. * @return string
  539. * @throws \think\db\exception\DataNotFoundException
  540. * @throws \think\db\exception\ModelNotFoundException
  541. * @throws \think\exception\DbException
  542. */
  543. public function scopeProfit(Query $query,$date=null){
  544. $profit=$query
  545. ->join('sender_order b','user_order.id=b.user_order_id and b.now=1')
  546. ->where('user_order.status',self::STATUS_SET)
  547. ->show()
  548. ->group('user_order.id')
  549. ->fieldRaw("(user_order.real_amount-SUM(b.fee_total)) AS profit,SUM(b.fee_total) as fee_total");
  550. if(is_null($date)){
  551. $profit->whereTime('user_order.created_at','today');
  552. }else{
  553. list($type,$time)=$date;
  554. if($type=='day'){
  555. $query->whereTime('user_order.created_at',$time);
  556. }elseif ($type=='month'){
  557. if (substr_count($time,'-')==1){
  558. $time="$time-01 00:00:00";
  559. }
  560. $query->whereBetween('user_order.created_at',[strtotime($time),strtotime("+1month",strtotime($time))]);
  561. }elseif ($type=='year'){
  562. $query->whereBetween('user_order.created_at',[strtotime("$time-01-01"),strtotime(($time+1).'-01-01')]);
  563. }
  564. }
  565. }
  566. /** 已付款 */
  567. public function scopeWaitGet(Query $query){
  568. $query
  569. ->show()
  570. ->where('status',self::STATUS_WAIT_GET)->show();
  571. }
  572. /** 已完成 */
  573. public function scopeSuccess(Query $query){
  574. $query
  575. ->show()
  576. ->whereBetween('status',[
  577. self::STATUS_COMPLETE,
  578. self::STATUS_WAIT_SET,
  579. ]);
  580. }
  581. /** 已结算
  582. * @param Query|static $query
  583. */
  584. public function scopeSettled(Query $query){
  585. $query
  586. ->whereIn('status',[self::STATUS_SET,self::STATUS_SET_REJECT]);
  587. }
  588. /**
  589. * 已取消
  590. * @param Query|self $query
  591. */
  592. public function scopeCanceled(Query $query){
  593. $query->where('status',self::STATUS_CANCEL);
  594. }
  595. /** 已超时 */
  596. public function scopeExpired(Query $query,$limit=10){
  597. $query->where('expired_at','<',time())
  598. ->where('status',self::STATUS_WAIT_PAY)
  599. ->order('id','desc')
  600. ->limit($limit);
  601. }
  602. /**
  603. * 已完成
  604. * @param Query|self $query
  605. */
  606. public function scopeOver(Query $query){
  607. $query
  608. ->show()
  609. ->whereBetween('status',[self::STATUS_COMPLETE,self::STATUS_SET_REJECT]);
  610. }
  611. /** 展示的 */
  612. public function scopeShow(Query $query){
  613. $query->whereNull("{$this->getTable()}.user_deleted_at");
  614. }
  615. /** 后台使用已完成 */
  616. public function scopeCompleted(Query $query){
  617. $query->where('status',UserOrder::STATUS_COMPLETE)
  618. ->show()
  619. ->order('id','desc');
  620. }
  621. /** 后台使用已结算 */
  622. public function scopeCaled(Query $query){
  623. $query->where('status',UserOrder::STATUS_SET)
  624. ->show()
  625. ->order('id','desc');
  626. }
  627. /** trashed */
  628. public static function withTrashed(){
  629. return new self;
  630. }
  631. }