cxfoot/modules/api/models/CommentForm.php
2023-10-27 14:25:12 +08:00

154 lines
4.4 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2020-12-2
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\api\models;
use app\models\DeviceUniqueBindUser;
use function AlibabaCloud\Client\value;
use app\components\FlashStorage;
use app\components\SiteHelper;
use app\models\Coach;
use app\models\Comment;
use app\models\Goods;
use app\models\GoodsHub;
use app\models\Store;
use app\models\User;
use app\components\auth\AToken;
use app\components\EncryptHelper;
use app\modules\api\components\ApiHelper;
use app\modules\api\components\GetDistance;
use yii\data\Pagination;
class CommentForm extends ApiModel
{
public $store_id;
public $cx_mch_id;
public $user_id;
public $to_user_id;
public $content;
public $device_id;
public $type;
public $level;
public function rules()
{
return [
[['user_id', 'to_user_id', 'store_id', 'content', 'device_id', 'type'], 'required'],
[['user_id', 'to_user_id', 'store_id', 'device_id', 'type', 'level'], 'integer'],
[['content'], 'string'],
];
}
/**
* 用户评价
*/
public function evaluation()
{
if (!$this->validate()) {
return $this->getModelError();
}
$to_user = ApiHelper::findOneUser($this->to_user_id);
if ($to_user == null) {
return $this->apiReturnError('教练已离职,无法评论');
}
if (!in_array($this->type, [1, 2])) {
return $this->apiReturnError('评价类型错误');
}
if ($this->type == 1) {
if (empty($this->level)) {
// return $this->apiReturnError('星级不能为空');
}
}
$commentModel = Comment::findOne(['user_id' => $this->user_id, 'store_id' => $this->store_id, 'device_id' => $this->device_id]);
if ($commentModel == null) {
$commentModel = new Comment();
}
$data = [];
$data['user_id'] = $this->user_id;
$data['to_user_id'] = $this->to_user_id;
$data['store_id'] = $this->store_id;
$data['content'] = $this->content;
$data['device_id'] = $this->device_id;
$data['type'] = $this->type;
$data['created_at'] = time();
if ($this->type == 1) {
$data['level'] = $this->level;
}
$commentModel->attributes = $data;
if (!$commentModel->save())
return $this->getModelError($commentModel);
return [
'code' => 0,
'msg' => '成功'
];
}
/**
* 评价查看
*/
public function evaluationList()
{
if (!$this->store_id) {
return $this->apiReturnError('门店ID不能为空');
}
if (!$this->device_id) {
return $this->apiReturnError('场次ID不能为空');
}
// 判断场次
$find = DeviceUniqueBindUser::findOne([
'id' => $this->device_id,
]);
if(empty($find)){
return $this->apiReturnError('场次不存在');
}
$list = [];
$list = Comment::find()->andWhere([
// 'user_id' => $this->user_id,
'store_id' => $this->store_id,
'device_id' => $this->device_id,
])->select('*')->asArray()->all();
$arr = [
'xy_data' => [],
'xy_status' => 0,
'jl_status' => 0,
'jl_data' => [],
'sf_status' => 1, # 其他身份
];
if($find->c_id != intval($this->user_id)){ // 不是教练
$arr['jl_status'] = 1;
if($find->uid != intval($this->user_id)){ // 不是学员
$arr['jl_status'] = 1;
}else{
$arr['sf_status'] = 2; # 学员身份
}
}
foreach ($list as $key=>$val){
if($val['type'] == 1){
$arr['xy_data'] = $val;
$arr['xy_status'] = 1;
}else{
$arr['jl_data'] = $val;
$arr['jl_status'] = 1;
}
}
$arr['param'] = ['user_id' => $this->user_id,
'store_id' => $this->store_id,
'device_id' => $this->device_id,$find->c_id];
return $this->apiReturnSuccess('ok', $arr);
}
}