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++; } } }