M230907013201FixQimallAddonsCouponUserRelateData.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace addons\Coupon\console\migrations;
  3. use addons\Coupon\common\models\AddonsCouponShareLog;
  4. use addons\Coupon\common\models\AddonsCouponUserRelate;
  5. use common\models\mall\Mall;
  6. use yii\db\Migration;
  7. /**
  8. * Class M230907013201FixQimallAddonsCouponUserRelateData
  9. */
  10. class M230907013201FixQimallAddonsCouponUserRelateData extends Migration
  11. {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function safeUp()
  16. {
  17. try {
  18. $malls = Mall::getEnableMallList();
  19. foreach ($malls as $mall) {
  20. $i = 1;
  21. $page_size = 10000;
  22. $list = AddonsCouponUserRelate::find()
  23. ->where(['coupon_status' => 4,'status'=>1,'is_giving'=>0,'giving_status'=>0,'mall_id'=>$mall['id']])
  24. ->offset(($i - 1) * $page_size)
  25. ->orderBy('id desc')
  26. ->limit($page_size)->all();
  27. foreach ($list as $model){
  28. $res = AddonsCouponShareLog::find()
  29. ->where(['user_coupon_id'=>$model['id']])
  30. ->andWhere(['<>','receive_user_id',0])->one();
  31. if(!empty($res)){
  32. $model->is_giving = 1;
  33. $model->giving_status = 2;
  34. $res = $model->save();
  35. if($res){
  36. var_dump($model['id']);
  37. }
  38. }
  39. }
  40. }
  41. }catch (\Exception $e){
  42. }
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function safeDown()
  48. {
  49. echo "M230907013201FixQimallAddonsCouponUserRelateData cannot be reverted.\n";
  50. return false;
  51. }
  52. /*
  53. // Use up()/down() to run migration code without a transaction.
  54. public function up()
  55. {
  56. }
  57. public function down()
  58. {
  59. echo "M230907013201FixQimallAddonsCouponUserRelateData cannot be reverted.\n";
  60. return false;
  61. }
  62. */
  63. }