Kaynağa Gözat

add - newDataExecute

liugc 1 yıl önce
ebeveyn
işleme
9b489e065b

+ 9 - 1
app/adminapi/controller/property/PropertyActivityController.php

@@ -30,7 +30,7 @@ use app\adminapi\validate\property\PropertyActivityValidate;
 class PropertyActivityController extends BaseAdminController
 {
 
-
+    public array $notNeedLogin = ['newDataExecute'];
     /**
      * @notes 获取列表
      * @return \think\response\Json
@@ -114,4 +114,12 @@ class PropertyActivityController extends BaseAdminController
         $params = (new PropertyActivityValidate())->post()->goCheck('detail');
         return $this->success('',['qrcode'=>PropertyActivityLogic::getQRCode($params,$this->request->domain())], 1, 1);
     }
+
+    // 上线前的旧数据处理为可用的新数据
+    public function newDataExecute()
+    {
+        dd(PropertyActivityLogic::newDataExecute());
+    }
+
+
 }

+ 32 - 0
app/adminapi/logic/property/PropertyActivityLogic.php

@@ -15,9 +15,11 @@
 namespace app\adminapi\logic\property;
 
 
+use app\common\model\coupon\CouponRules;
 use app\common\model\property\PropertyActivity;
 use app\common\logic\BaseLogic;
 use app\common\service\wechat\WeChatMnpService;
+use think\db\Query;
 use think\Exception;
 use think\facade\Db;
 use think\facade\Log;
@@ -183,5 +185,35 @@ class PropertyActivityLogic extends BaseLogic
     }
 
 
+    public static function newDataExecute()
+    {
+        try {
+            $activity_list = PropertyActivity::select()->toArray();
+            foreach ($activity_list as $item) {
+                if(!empty($itemp['coupon_data'])){
+                    continue;
+                }
+                $coupon_list =  CouponRules::with(['couponWithCategory'=>function(Query $query){
+                                        $query->field('id,name');
+                                }])->where('property_activity_id',$item['id'])
+                                ->field(['id','code', 'amount', 'coupon_type','amount_require', 'discount_ratio', 'event_name', 'expire_time', 'max_deductible_price', 'mold_type', 'server_category_name', 'voucher_status', 'voucher_count','remaining_count','property_activity_id'])
+                                ->select()
+                                ->toArray()??[];
+                foreach($coupon_list as $k => $v){
+                    $v['goods_category_ids'] = array_column($v['couponWithCategory'],'id');
+                    $coupon_list[$k] = $v;
+                }
+                if($coupon_list){
+                    $data = [
+                        'coupon_data' => json_encode(self::configureReservedField($coupon_list??[], 'coupon_data')),
+                    ];
+                    PropertyActivity::where('id',$item['id'])->update($data);
+                }
+            }
+            return true;
+        } catch (\Throwable $e) {
+            return $e->getMessage();
+        }
+    }
 
 }