| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace addons\Coupon\console\migrations;
- use addons\Coupon\common\models\AddonsCouponShareLog;
- use addons\Coupon\common\models\AddonsCouponUserRelate;
- use common\models\mall\Mall;
- use yii\db\Migration;
- /**
- * Class M230907013201FixQimallAddonsCouponUserRelateData
- */
- class M230907013201FixQimallAddonsCouponUserRelateData extends Migration
- {
- /**
- * {@inheritdoc}
- */
- public function safeUp()
- {
- try {
- $malls = Mall::getEnableMallList();
- foreach ($malls as $mall) {
- $i = 1;
- $page_size = 10000;
- $list = AddonsCouponUserRelate::find()
- ->where(['coupon_status' => 4,'status'=>1,'is_giving'=>0,'giving_status'=>0,'mall_id'=>$mall['id']])
- ->offset(($i - 1) * $page_size)
- ->orderBy('id desc')
- ->limit($page_size)->all();
- foreach ($list as $model){
- $res = AddonsCouponShareLog::find()
- ->where(['user_coupon_id'=>$model['id']])
- ->andWhere(['<>','receive_user_id',0])->one();
- if(!empty($res)){
- $model->is_giving = 1;
- $model->giving_status = 2;
- $res = $model->save();
- if($res){
- var_dump($model['id']);
- }
- }
- }
- }
- }catch (\Exception $e){
- }
- }
- /**
- * {@inheritdoc}
- */
- public function safeDown()
- {
- echo "M230907013201FixQimallAddonsCouponUserRelateData cannot be reverted.\n";
- return false;
- }
- /*
- // Use up()/down() to run migration code without a transaction.
- public function up()
- {
- }
- public function down()
- {
- echo "M230907013201FixQimallAddonsCouponUserRelateData cannot be reverted.\n";
- return false;
- }
- */
- }
|