MobileOrder.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\common\model;
  3. use app\admin\model\Admin;
  4. use think\db\Query;
  5. use think\Model;
  6. /**
  7. * 配置模型
  8. */
  9. class MobileOrder extends Model
  10. {
  11. const STATUS_WAIT_SEND=10;
  12. public static $status=[
  13. 0=>'待付款',
  14. 10=>'待发货',
  15. 20=>'待收货',
  16. 30=>'退款待处理',
  17. 40=>'已退款',
  18. 50=>'已关闭',
  19. ];
  20. // 自动写入时间戳字段
  21. protected $autoWriteTimestamp = true;
  22. public function mobile(){
  23. return $this->belongsTo(Mobile::class);
  24. }
  25. public function proxy(){
  26. $columns=Admin::getTableInfo()['fields'];
  27. unset($columns['password']);
  28. return $this->belongsTo(Admin::class)->field($columns);
  29. }
  30. public function getAddressAttr($a,$b){
  31. return Area::getNameString($b['city']).$a;
  32. }
  33. protected static function init()
  34. {
  35. self::beforeInsert(function (self $mobileOrder){
  36. $mobileOrder['order_no']=order_no();
  37. $mobileOrder['expire_time']=time()+86400;
  38. });
  39. }
  40. public function scopeExpired(Query $query){
  41. $query->where('status',0)->where('expire_time','<',time());
  42. }
  43. public function cancel(){
  44. if($this['pay_time'] || $this['pay_time']!=0){
  45. return;
  46. }
  47. $this['status']=50;
  48. $this->save();
  49. }
  50. }