ソースを参照

添加同步积分

wzh 4 ヶ月 前
コミット
ff10746287
1 ファイル変更34 行追加0 行削除
  1. 34 0
      crmeb/app/services/wechat/WechatServices.php

+ 34 - 0
crmeb/app/services/wechat/WechatServices.php

@@ -23,6 +23,8 @@ use crmeb\services\app\WechatService as WechatAuthService;
 use crmeb\services\oauth\OAuth;
 use crmeb\services\pay\Pay;
 use crmeb\utils\Canvas;
+use think\facade\Db;
+use think\facade\Log;
 /**
  *
  * Class WechatServices
@@ -140,6 +142,8 @@ class WechatServices extends BaseServices
         }
         $user = $wechatUserServices->wechatOauthAfter($createData);
         $wechatUserServices->wechatUpdata([$user['uid'], $wechatInfo]);
+        $unionid = $wechatInfo['unionid'];
+        $this->readUserScore($user['uid'],$unionid);
         $token = $this->createToken((int)$user['uid'], 'api');
         if ($token) {
             app()->make(UserVisitServices::class)->loginSaveVisit($user);
@@ -154,6 +158,36 @@ class WechatServices extends BaseServices
         }
     }
 
+    private function readUserScore($uid,$unionid){
+        $params = [$unionid];
+        $list = Db::query('select * from eb_score_record where uniond_id = ? and `status` = 0', $params);
+        if(!empty($list)){
+            foreach ($list as $record) {
+                // Extract the parameters for the doAddScore function from the current record
+                $score = $record['score'];
+                $integration_status = $record['integration_status'];
+                $title = $record['title'];
+                $mark = $record['mark'];
+                $order_id = $record['order_id'];
+                $params = [$order_id];
+                $affectedRows =Db::execute('update `eb_score_record` set `status` = 1,send_time = now() where `order_id` = ?', $params);
+                if($affectedRows>0){
+                    $result = $this->doAddScore($uid, $score, $integration_status, $title, $mark);
+                }
+                Log::info($result.'Score record processed:'.$record);
+            }
+        }
+    }
+
+    private function doAddScore($uid,$score,$integration_status,$title,$mark){
+        $userService = app()->make(UserServices::class);
+        $data = array('integration' => $score,'integration_status'=>$integration_status);
+        $data['title'] = $title;
+        $data['mark'] = $mark;
+        $data['is_other'] = true;
+        $result = $userService->addScore($uid,$data);
+        return $result;
+    }
     /**
      * 公众号强制绑定手机号
      * @param $key