156 lines
4.9 KiB
PHP
156 lines
4.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-23
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\models\coupon;
|
|
|
|
use app\models\Banner;
|
|
use app\models\Model;
|
|
use app\modules\admin\models\AdminModel;
|
|
|
|
class CouponEditForm extends AdminModel
|
|
{
|
|
|
|
public $model;
|
|
|
|
public $type;
|
|
public $title;
|
|
public $price;
|
|
public $num;
|
|
public $get_start_time;
|
|
public $get_end_time;
|
|
public $start_time;
|
|
public $end_time;
|
|
|
|
public $created_at;
|
|
public $updated_at;
|
|
public $is_delete;
|
|
public $deleted_at;
|
|
|
|
public $vehicle_ids;
|
|
|
|
public $store_ids;
|
|
public $user_get_num;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['title', 'start_time', 'end_time', 'type','get_start_time','get_end_time','num','user_get_num'], 'required'],
|
|
[['num', 'type', 'created_at', 'updated_at', 'is_delete', 'deleted_at'], 'integer'],
|
|
[['price'], 'number'],
|
|
[['store_ids'], 'safe'],
|
|
[['title'], 'string', 'max' => 50],
|
|
[['num'], 'integer', 'min' => -1],
|
|
[['get_start_time', 'get_end_time','start_time', 'end_time',], 'date', 'format' => 'php:Y-m-d'],
|
|
[['vehicle_ids', ], 'string', 'max' => 255],
|
|
];
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'id' => 'ID',
|
|
'title' => '卡券标题',
|
|
'start_time' => '使用开始时间',
|
|
'end_time' => '使用结束时间',
|
|
'price' => '金额',
|
|
'num' => '发放数量',
|
|
'type' => '类型0=体验券1=立减券',
|
|
'vehicle_ids' => '指定球车使用,为空则不限制',
|
|
'created_at' => 'Created At',
|
|
'updated_at' => 'Updated At',
|
|
'is_delete' => 'Is Delete',
|
|
'deleted_at' => 'Deleted At',
|
|
'get_start_time' => '领取开始时间',
|
|
'get_end_time' => '领取结束时间',
|
|
'store_ids' => '可使用门店',
|
|
'user_get_num' => '用户可领取数量',
|
|
];
|
|
}
|
|
|
|
|
|
public function edit()
|
|
{
|
|
if(!$this->validate()){
|
|
return $this->getModelError();
|
|
}
|
|
if($this->model->isNewRecord){
|
|
$this->model->created_at = time();
|
|
$this->model->is_delete = 0;
|
|
$this->model->deleted_at = 0;
|
|
}
|
|
|
|
if($this->type == '1' && (empty($this->price) || $this->price < 0.01)){
|
|
return self::asReturnError('立减券金额必须设置,且金额需大于0');
|
|
}
|
|
|
|
if(empty($this->user_get_num) || !is_numeric($this->user_get_num)){
|
|
return self::asReturnError('用户可领取数量必须大于0,且必须为整数');
|
|
}
|
|
if(!is_numeric($this->num)){
|
|
return self::asReturnError('发放数量必须为整数');
|
|
}
|
|
if($this->num < 0){
|
|
$this->num = -1;
|
|
}
|
|
|
|
|
|
$get_start_time = strtotime($this->get_start_time);
|
|
$get_end_time = strtotime($this->get_end_time);
|
|
|
|
$start_time = strtotime($this->start_time);
|
|
$end_time = strtotime($this->end_time);
|
|
|
|
if($get_start_time == $get_end_time){
|
|
return self::asReturnError('领取开始日期不能与结束日期一致,请重新选择');
|
|
}
|
|
if($start_time == $end_time){
|
|
return self::asReturnError('有效开始日期不能与有效结束日期一致,请重新选择');
|
|
}
|
|
|
|
//领取结束时间必须比当前时间大
|
|
if($get_end_time <= time()){
|
|
return self::asReturnError('领取日期属于无效范围,请重新选择');
|
|
}
|
|
|
|
//使用结束日期必须比当前时间大
|
|
if($end_time <= time()){
|
|
return self::asReturnError('使用日期属于无效范围,请重新选择');
|
|
}
|
|
|
|
//领取结束时间必须在使用结束日期内
|
|
if($get_end_time > $end_time){
|
|
return self::asReturnError('领取结束时间必须小于使用结束时间');
|
|
}
|
|
|
|
$this->model->updated_at = time();
|
|
$this->model->title = $this->title;
|
|
$this->model->type = $this->type;
|
|
$this->model->start_time = $start_time;
|
|
$this->model->end_time = $end_time;
|
|
$this->model->price = empty($this->price) ? 0 : $this->price;
|
|
$this->model->num = $this->num;
|
|
$this->model->vehicle_ids = '';
|
|
$this->model->get_start_time = $get_start_time;
|
|
$this->model->get_end_time = $get_end_time;
|
|
$this->model->user_get_num = $this->user_get_num;
|
|
if(!empty($this->store_ids)){
|
|
$this->model->store_ids = implode(',',$this->store_ids);
|
|
}
|
|
if(!$this->model->save()){
|
|
return self::getModelErrorInfo($this->model);
|
|
}
|
|
return self::asReturnSuccess('创建成功');
|
|
|
|
|
|
}
|
|
|
|
|
|
} |