cxfoot/models/common/CommonFeedbackSubmitForm.php
2023-10-24 14:54:18 +08:00

111 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* @author Any
* @description KISS
* @date 2021年6月29日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\models\common;
use app\models\Feedback;
use app\models\Cat;
use app\models\User;
use app\models\Model;
use app\components\SiteHelper;
class CommonFeedbackSubmitForm extends Model
{
public $cx_mch_id;
public $cat_id;
public $contact;
public $content;
public $user_id;
public $pic_list;
public function rules()
{
return [
[['contact', 'content', 'pic_list'], 'trim'],
[['contact', 'content', 'pic_list'], 'string'],
[['cx_mch_id', 'cat_id', 'user_id'], 'integer'],
[['cx_mch_id', ], 'required'],
[['cat_id', 'user_id', 'contact', 'content', 'pic_list'], 'required', 'on' => 'submit'],
];
}
public function attributeLabels()
{
return [
'cx_mch_id' => '平台商户ID',
'cat_id' => '分类ID',
'contact' => '联系方式QQ|手机号',
'content' => '反馈内容',
'pic_list' => '反馈图片',
];
}
public function save()
{
if(!$this->validate()){
return $this->getModelError();
}
if(!empty($this->cat_id)){
$cat = Cat::findOne([
'type' => Cat::TYPE_FEEDBACK,
'id' => $this->cat_id,
'is_delete' => 0,
'status' => 1,
]);
if($cat == null){
return $this->apiReturnError("反馈分类不存在");
}
}
$pic_list = json_decode($this->pic_list);
if(!is_array($pic_list)){
return $this->apiReturnError("反馈图片列表无效数据格式");
}
if(count($pic_list) == 0){
return $this->apiReturnError("反馈图片不能为空");
}
foreach ($pic_list as $index => $pic){
$pic_list[$index] = SiteHelper::getRelativeUrl($pic);
}
$this->pic_list = json_encode($pic_list,JSON_UNESCAPED_UNICODE);
$model = new Feedback();
$model->attributes = $this->attributes;
$model->review_user_id = 0;
$model->review_status = Feedback::REVIEW_STATUS_WAITTING;
$model->review_time = 0;
if(!$model->save()){
return $this->getModelError($model);
}
return $this->apiReturnSuccess("反馈提交成功");
}
public function search()
{
if(!$this->validate()){
return $this->getModelError();
}
$cat_list = Cat::find()
->where([
'cx_mch_id' => $this->cx_mch_id,
'is_delete' => 0,
'type' => Cat::TYPE_FEEDBACK,
])
->orderBy(['sort' => SORT_ASC, 'created_at' => SORT_DESC])
->select('id,name,img_url')->asArray()->all();
foreach($cat_list as $index => $item){
$item['img_url'] = SiteHelper::getFullUrl($item['img_url']);
$cat_list[$index] = $item;
}
return $this->apiReturnSuccess("ok", ['cat_list' => $cat_list]);
}
}