初始化仓库
This commit is contained in:
80
admin/models/forms/ActivityForm.php
Normal file
80
admin/models/forms/ActivityForm.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace admin\models\forms;
|
||||
|
||||
use common\models\Activity;
|
||||
use common\validators\MobieValidator;
|
||||
use Yii;
|
||||
use common\core\BaseModel;
|
||||
use yii\base\Exception;
|
||||
|
||||
class ActivityForm extends BaseModel
|
||||
{
|
||||
public $id;
|
||||
public $mall_id;
|
||||
public $title;
|
||||
public $price;
|
||||
public $start_time;
|
||||
public $end_time;
|
||||
public $p_commission;
|
||||
public $pp_commission;
|
||||
public $content;
|
||||
|
||||
public $contact;
|
||||
public $mobile;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['id','default','value'=>0],
|
||||
[['mall_id','title','contact','mobile','price','start_time','end_time','p_commission','pp_commission'],'required'],
|
||||
['content','default','value'=>''],
|
||||
['mobile',MobieValidator::class,'message'=>'手机号格式不正确'],
|
||||
[['price'],'number','min'=>0],
|
||||
[['p_commission','pp_commission'],'number','min'=>1],
|
||||
[['p_commission','pp_commission'], 'match', 'pattern' => '/^\d+(\.\d{1,2})?$/i','message'=>'佣金最多只能有两位小数']
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'mall_id' => '活动门店',
|
||||
'title' => '活动标题',
|
||||
'contact' => '联系人',
|
||||
'mobile' => '联系电话',
|
||||
'price' => '活动价格',
|
||||
'start_time' => '活动开始时间',
|
||||
'end_time' => '活动结束时间',
|
||||
'p_commission' => '上级返佣',
|
||||
'pp_commission' => '上上级返佣'
|
||||
];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
throw new Exception($this->getErrorMsg($this));
|
||||
}
|
||||
if($this->id){
|
||||
$model = Activity::find()->where([
|
||||
'id' => $this->id,
|
||||
'is_delete' => 0
|
||||
])->one();
|
||||
if(!$model){
|
||||
throw new Exception('活动不存在');
|
||||
}
|
||||
}else{
|
||||
$model = new Activity();
|
||||
}
|
||||
$model->attributes = $this->attributes;
|
||||
$model->start_time = strtotime($this->start_time);
|
||||
$model->end_time = strtotime($this->end_time);
|
||||
$model->saveOrFail();
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user