| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- <?php
- namespace common\models\order;
- use addons\Store\common\models\Store;
- use addons\Store\common\models\StoreGoods;
- use addons\Store\common\models\StoreOrderDetail;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\goods\Goods;
- use common\models\user\User;
- use PHPUnit\Util\Exception;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "qimall_order_comments".
- *
- *
- * @property int $id
- * @property int $mall_id
- * @property int $mch_id
- * @property int $store_id
- * @property int $order_id
- * @property int|null $order_detail_id 订单详情id
- * @property int $goods_id 商品ID
- * @property int $user_id 会员id
- * @property int $score 评分:1=差评,2,3=中评,4,5=好
- * @property string $content 评价内容
- * @property string $pic_url 评价图片
- * @property int $is_top 是否置顶0.否|1.是
- * @property string $reply_content 商家回复内容
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- * @property int $is_virtual 是否虚拟用户
- * @property string $virtual_user 虚拟用户名
- * @property string $virtual_avatar 虚拟头像
- * @property int $virtual_time 虚拟评价时间
- */
- class OrderComments extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%order_comments}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'mch_id','store_id', 'order_id', 'order_detail_id', 'goods_id', 'user_id', 'score', 'is_top',
- 'status', 'created_at', 'updated_at', 'is_virtual', 'virtual_time','goods_type'], 'integer'],
- [['score'], 'required'],
- [['content', 'pic_url'], 'string', 'max' => 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++;
- }
- }
- }
|