cxhxy/app/common/model/food/FoodCouponUserWx.php
2024-01-03 14:19:05 +08:00

74 lines
1.6 KiB
PHP

<?php
namespace app\common\model\food;
use Endroid\QrCode\QrCode as CodeMode;
use Endroid\QrCode\Writer\PngWriter;
use think\facade\Db;
/**
* 线下发券模型
*/
class FoodCouponUserWx extends BaseModel
{
// 定义表名
protected $name = 'food_coupon_user_wx';
// 定义主键
protected $pk = 'coupon_user_id';
// 追加字段
protected $append = ['userdata'];
/**
* 到期时间
*/
public function getExpireTimeAttr($value)
{
$time = $value - time();
if($time > 86400){
$text = round($time / 86400) . '天';
}elseif($time > 3600){
$text = round($time / 3600) . '小时';
}elseif($time > 60){
$text = round($time / 60) . '分钟';
}else{
$text = '已过期';
}
return ['text' => $text, 'value' => $value];
}
/**
* 状态
*/
public function getStatusAttr($value)
{
$status = [1 => '待使用', 2 => '已使用'];
return ['text' => $status[$value], 'value' => $value];
}
/**
* 用户数据
*/
public function getUserdataAttr($value,$data)
{
return Db::name('user_wx')->where('wx_openid',$data['openid'])->find();
}
/**
* 获取列表
*/
public function getList()
{
//提前3分钟删除即将到期未领取优惠券
return $this->order('coupon_user_id','desc')
->paginate(['list_rows'=>15,'query' => request()->param()]);
}
/**
* 删除
*/
public function remove()
{
return $this->delete();
}
}