5000], [['reply_content'], 'string', 'max' => 1000], [['virtual_user', 'virtual_avatar'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'mch_id' => '多商户id', 'store_id' => '门店id', 'order_id' => '订单id', 'order_detail_id' => '订单详情id', 'goods_id' => '商品ID', 'user_id' => '会员id', 'score' => '评分:1=差评,2,3=中评,4,5=好', 'content' => '评价内容', 'pic_url' => '评价图片', 'is_top' => '是否置顶0.否|1.是', 'reply_content' => '商家回复内容', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '创建时间', 'updated_at' => '修改时间', 'is_virtual' => '是否虚拟用户', 'virtual_user' => '虚拟用户名', 'virtual_avatar' => '虚拟头像', 'virtual_time' => '虚拟评价时间', ]; } public function getGoods() { return $this->hasOne(Goods::class, ['id' => 'goods_id']); } public function getUsers() { return $this->hasOne(User::class, ['id' => 'user_id']); } public function getReserveComment() { return $this->hasOne(OrderReserveComments::class, ['id' => 'id']); } public function getOrder() { return $this->hasOne(Order::class, ['id' => 'order_id']); } public function getOrderDetail() { return $this->hasOne(OrderDetail::class, ['id' => 'order_detail_id']); } /** * @Author: hua * @DateTime: 2021/10/8 9:41 * @Copyright: copyright (c) 2021 广东七件事集团 * @param array $params * @return bool|OrderComments * @throws \yii\db\Exception */ public static function setData(array $params) { try { if (!empty($params['id'])) { $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); if (empty($model)) throw new Exception('服务不存在或已删除'); } else { $model = new self(); $model->loadDefaultValues(); } if (isset($params['pic_url'])) $params['pic_url'] = Json::encode($params['pic_url']);//后台虚拟 if (isset($params['pic_list'])) $params['pic_url'] = $params['pic_list'];//前端真实用户 if (!empty($params['virtual_time'])) $params['virtual_time'] = strtotime($params['virtual_time']); if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage()); $res = OrderDetail::setData(['id' => $params['order_detail_id'], 'mall_id' => $params['mall_id'], 'is_evaluate' => 1]); if (!$res) throw new Exception(OrderDetail::getStaticError()); return $model; } catch (Exception $e) { self::$static_error = $e->getMessage(); return false; } } /** * * @Author: hua * @DateTime: 2021/10/7 16:41 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $params * @return bool|OrderComments * @throws \Exception */ public static function updateData($params) { try { $res = self::updateAll($params['field'], ['in', 'id', $params['id']]); if (!$res) throw new Exception(self::getStaticError()); return true; } catch (Exception $e) { self::$static_error = $e->getMessage(); return false; } } public static function updateGoodsType() { $i = 1; $page = 500; while(true){ $offset = ($i-1)*$page; $list = self::find()->where(['>','mall_id',0])->offset($offset)->limit($page)->all(); if(empty($list)){ break; } $goods_ids = $store_goods_ids = []; foreach ($list as $item){ if(!empty($item['store_id'])){ $store_goods_ids[]=$item['goods_id']; }else{ $goods_ids[]=$item['goods_id']; } } if(!empty($store_goods_ids)){ $store_goods_list = StoreGoods::lists([ 'where'=>[ ['id'=>$store_goods_ids] ], 'index'=>'id', 'select'=>'id,goods_type' ]); } if(!empty($store_goods_ids)){ $goods_list = Goods::lists([ 'where'=>[ ['id'=>$goods_ids] ], 'index'=>'id', 'select'=>'id,goods_type' ]); } foreach ($list as $item){ if(!empty($item['store_id'])){ $item->goods_type = $store_goods_list[$item['goods_id']]['goods_type']??1; }else{ $item->goods_type = $goods_list[$item['goods_id']]['goods_type']??1; } $item->save(); } $i++; } } }