wangxiaodong 3 years ago
parent
commit
b4fe5850d0
1 changed files with 26 additions and 3 deletions
  1. 26 3
      addon/pointexchange/model/OrderCreate.php

+ 26 - 3
addon/pointexchange/model/OrderCreate.php

@@ -108,13 +108,36 @@ class OrderCreate extends BaseModel
 				return $result;
 			}
 			if ($calculate_data["exchange_type"] == 1){
+                $member_info = model('member')->getInfo(['member_id' => $data['member_id']],'username, mobile, email,currency,point');
+                if ($member_info['point'] < $calculate_data['point']){
+                    model("promotion_exchange_order")->rollback();
+                    return success(1,'积分不足');
+                }
+                $a = model('member')->setDec(['member_id'=>$data['member_id']],'point',$calculate_data["currency"]);
+                $account_data['member_id'] = $data['member_id'];
+                $account_data['account_type'] = 'point';
+                $account_data['account_data'] = '-'.$calculate_data["point"];
+                $account_data['from_type'] = 'order';
+                $account_data['type_name'] = '积分兑换';
+                $account_data['remark'] = '积分兑换扣除积分:'.$calculate_data["point"];
+                $account_data['create_time'] = time();
+                $account_data['username'] = $member_info['username'];
+                $account_data['mobile'] = $member_info['mobile'];
+                $account_data['email'] = $member_info['email'];
+                $b = model('member_account')->add($account_data);
+
+                if (!$a || !$b) {
+                    model("promotion_exchange_order")->rollback();
+                    return success(1,'操作失败');
+                }
+
                 //扣除积分
-                $member_account_model = new MemberAccount();
+                /*$member_account_model = new MemberAccount();
                 $member_account_result = $member_account_model->addMemberAccount($data["member_id"], "point", -$calculate_data["point"], "order", "积分兑换", "积分兑换,扣除积分:" . $calculate_data["point"]);
                 if ($member_account_result["code"] < 0) {
                     model("promotion_exchange_order")->rollback();
                     return $result;
-                }
+                }*/
 
             }else{
 
@@ -153,7 +176,7 @@ class OrderCreate extends BaseModel
 			return $this->success($out_trade_no);
 
 		} catch (\Exception $e) {
-		    echo "<pre>";print_r('111');exit;
+		    //echo "<pre>";print_r('111');exit;
 			model("promotion_exchange_order")->rollback();
 			return $this->error('', $e->getMessage());
 		}