lizhen_gitee 1 سال پیش
والد
کامیت
8c8e25ea6d
2فایلهای تغییر یافته به همراه19 افزوده شده و 40 حذف شده
  1. 13 16
      application/api/controller/Gift.php
  2. 6 24
      application/common/model/Wallet.php

+ 13 - 16
application/api/controller/Gift.php

@@ -10,16 +10,13 @@ use think\Db;
  */
 class Gift extends Api
 {
-    protected $noNeedLogin = ['getGiftList','getGiftType'];
+    protected $noNeedLogin = [];
     protected $noNeedRight = '*';
-    public $giftModel;
-    public $gifttypeModel;
+
 
     public function _initialize()
     {
         parent::_initialize();
-        $this->giftModel = new \app\common\model\Gift();
-        $this->gifttypeModel = new \app\common\model\GiftType();
     }
 
     /**
@@ -82,7 +79,7 @@ class Gift extends Api
         {
             $this->error("请选择礼物");
         }
-        $giftvalue = bcmul($giftinfo['value'],$number);
+        $giftvalue = bcmul($giftinfo['price'],$number);
 
         //被赠送人信息
         $touserinfo = Db::name('user')->where('id',$user_id)->find();
@@ -104,13 +101,14 @@ class Gift extends Api
 
         // 添加礼物赠送记录表
         $data = [
-            'user_id' => $this->auth->id,
-            'user_to_id' => $user_id,
-            'gift_id' => $giftinfo['id'],
-            'gift_name' => $giftinfo['name'],
-            'number' => $number,
-            'price' => $giftvalue,
-            'createtime' => time(),
+            'user_id'     => $this->auth->id,
+            'user_to_id'  => $user_id,
+            'gift_id'     => $giftinfo['id'],
+//            'gift_name'  => $giftinfo['name'],
+            'number'      => $number,
+            'price'       => $giftinfo['price'],
+            'total_price' => $giftvalue,
+            'createtime'  => time(),
         ];
         $log_id = Db::name('gift_user_typing')->insertGetId($data);
         if(!$log_id){
@@ -118,7 +116,6 @@ class Gift extends Api
             $this->error('赠送失败');
         }
 
-
         if($giftvalue > 0){
 
             // 扣除当前用户余额
@@ -144,11 +141,11 @@ class Gift extends Api
 
         //tag任务赠送金币
         //搭讪奖励
-        $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
+        /*$task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
         if($task_rs === false){
             Db::rollback();
             $this->error('完成任务赠送奖励失败');
-        }
+        }*/
 
         Db::commit();
         $this->success('赠送成功');

+ 6 - 24
application/common/model/Wallet.php

@@ -119,7 +119,8 @@ class Wallet extends Model
                 $data = array();
                 $data['user_id'] = $user_id;
                 $data['log_type'] = $logtype;
-                $data['money_type'] = $accountType;
+//                $data['money_type'] = $accountType;
+                $data['before'] = $wallet[$accountType];
                 $data['change_value'] = $number;
                 $data['remain'] = bcadd($wallet[$accountType], $number);
                 $data['table'] = $table;
@@ -129,18 +130,13 @@ class Wallet extends Model
                 $data['updatetime'] = time();
 
                 //新的方式
-                if(bccomp($number, 0) === 1){
-                    $rs1 = Db::name('user_wallet')->where(['user_id'=>$user_id])->setInc($accountType,$number);
-                }else{
-                    $rs1 = Db::name('user_wallet')->where(['user_id'=>$user_id])->setDec($accountType,abs($number));
-                }
+                $rs1 = Db::name('user_wallet')->where(['user_id'=>$user_id])->update([$accountType => $data['remain']]);
+
 
 
                 /////////////
-                $log_table = 'user_money_log';
-                if($accountType == 'gold'){
-                    $log_table = 'user_gold_log';
-                }
+                $log_table = 'user_'.$accountType.'_log';
+
                 $rs2_id = Db::name($log_table)->insertGetId($data);
 
                 if($rs1 === false || $rs2_id === false){
@@ -150,20 +146,6 @@ class Wallet extends Model
 
                 if( $rs1 !== false && $rs2_id !== false )
                 {
-                    //金额变动
-                    /*$params = [
-                        'msg' => '您的钱包['.$wallet_name.']有变化,请注意查看',
-                        'description' => '您的钱包['.$wallet_name.']有变化:'.$number.'剩余:'.$data['remain'],
-                        'content' => '您的钱包['.$wallet_name.']有变化:'.$number.',剩余:'.$data['remain'].',备注:'.$remark,
-                        'user_id' => $user_id,
-                        'status' => 1,
-                        'comefrom' => '系统',
-                        'type' => '钱包',
-                        'createtime' => time(),
-                        'important' => 3,
-                    ];
-                    Db::name('system_msg')->insertGetId($params);*/
-
                     $result['status'] = true;
                     $result['msg'] = '账户余额已更新!';
                     $result['log_table'] = $accountType.'_log';