| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- namespace common\models\order;
- use addons\Store\common\models\Store;
- 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 common\models\order\OrderComments;
- 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 OrderCommentsExtra extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%order_comments_extra}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'mch_id','store_id', 'goods_id', 'created_at', 'updated_at', 'num'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['id' => 'goods_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 {
- $model = new self();
- $model->loadDefaultValues();
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- 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 updateOldData()
- {
- $i = 1;
- $page_size = 1000;
- while ($list = OrderComments::find()
- ->select('mall_id,store_id,goods_id,user_id,mch_id,count(*) as num')
- ->groupBy('goods_id,mch_id,store_id,user_id')
- ->offset(($i - 1) * $page_size)->limit($page_size)->all()) {
- $data = [];
- foreach ($list as $key => $value) {
- $data[$value['mall_id'].'_'.$value['store_id'].'_'.$value['mch_id'].'_'.$value['goods_id']] += 1;
- }
- if (!empty($data)) {
- foreach ($data as $k => $val) {
- $key_arr = explode('_', $k);
- $params = [
- 'mall_id' => $key_arr[0],
- 'store_id' => $key_arr[1],
- 'mch_id' => $key_arr[2],
- 'goods_id' => $key_arr[3],
- 'num' => $val,
- ];
- var_dump($params);
- $res = self::setData($params);
- if (!$res) {
- var_dump(self::$static_error);
- }
- }
- }
- $i++;
- }
- }
- }
|