| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace addons\ScoreMall\common\models;
- use common\models\base\BaseActiveRecord;
- use Exception;
- use Yii;
- /**
- * This is the model class for table "{{%addons_score_mall_exchange_record}}".
- * @property int $id
- * @property int $mall_id
- * @property int $user_id
- * @property int $goods_id 商品ID
- * @property int $goods_attr_id 属性ID
- * @property string $exchange_price 兑换价格
- * @property string $goods 商品信息
- * @property int $order_id
- * @property int $num 兑换数量
- * @property string $order_no 订单号
- * @property int $status
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class ScoreMallExchangeRecord extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_score_mall_exchange_record}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules(){
- return [
- [['mall_id', 'user_id'], 'required'],
- [['mall_id', 'user_id', 'status', 'created_at', 'updated_at', 'goods_id', 'goods_attr_id', 'num', 'order_id'], 'integer'],
- [['order_no'], 'string', 'max' => 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++;
- }
- }
- }
|