123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\common\model;
- use app\admin\model\Admin;
- use think\db\Query;
- use think\Model;
- /**
- * 配置模型
- */
- class MobileOrder extends Model
- {
- const STATUS_WAIT_SEND=10;
- public static $status=[
- 0=>'待付款',
- 10=>'待发货',
- 20=>'待收货',
- 30=>'退款待处理',
- 40=>'已退款',
- 50=>'已关闭',
- ];
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- public function mobile(){
- return $this->belongsTo(Mobile::class);
- }
- public function proxy(){
- $columns=Admin::getTableInfo()['fields'];
- unset($columns['password']);
- return $this->belongsTo(Admin::class)->field($columns);
- }
- public function getAddressAttr($a,$b){
- return Area::getNameString($b['city']).$a;
- }
- protected static function init()
- {
- self::beforeInsert(function (self $mobileOrder){
- $mobileOrder['order_no']=order_no();
- $mobileOrder['expire_time']=time()+86400;
- });
- }
- public function scopeExpired(Query $query){
- $query->where('status',0)->where('expire_time','<',time());
- }
- public function cancel(){
- if($this['pay_time'] || $this['pay_time']!=0){
- return;
- }
- $this['status']=50;
- $this->save();
- }
- }
|