64], [['exchange_price','goods'], 'string'], ]; } /** * {@inheritdoc} */ public function attributeLabels(){ return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'order_no' => '订单号', 'order_id' => '订单ID', 'goods_id' => '商品ID', 'goods_attr_id' => '属性ID', 'exchange_price'=> '兑换价格', 'goods' => '商品信息', 'num' => '兑换数量', 'status' => '状态[-1:删除;0:禁用;1启用]', 'created_at' => '创建时间', 'updated_at' => '修改时间' ]; } /** * 保存数据 * @Author: lun * @DateTime: 2022/1/12 0012 19:27 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $params * @return bool */ public static function setData($params) { try { $model = new self(); $model->loadDefaultValues(); if (!$model->load($params, '')) throw new Exception($model->getErrorMessage()); if (!$model->save()) throw new Exception($model->getErrorMessage()); return true; } catch (Exception $e) { self::setStaticError($e->getMessage()); return false; } } public static function fixExchangePrice(){ $i = 1; $page_size = 1000; while ($list = self::find()->where(['>', 'mall_id', 0]) ->offset(($i - 1) * $page_size)->limit($page_size)->all()) { $order_ids = array_column($list,'order_id'); $order_list = \common\models\order\Order::lists(['where'=>[['id'=>$order_ids]],'index'=>'id']); foreach ($list as $item) { if(empty($order_list[$item['order_id']])) continue; $order = $order_list[$item['order_id']]; $exchange_price = $order['extra_info']; $extra_info = json_decode($order['extra_info'],true); if(!empty($extra_info)&&is_array($extra_info)){ $exchange_price = $extra_info[0]??''; } if($exchange_price !=$item['exchange_price']){ $item->exchange_price = $exchange_price; $res = $item->save(); var_dump($res); } } $i++; } } }