lizhen_gitee 1 year ago
parent
commit
87bac7df83

+ 2 - 2
application/api/controller/Article.php

@@ -6,7 +6,7 @@ use app\common\controller\Api;
 use think\Db;
 use addons\epay\library\Service;
 /**
- * 首页产品
+ * 首页产品文章
  */
 class Article extends Api
 {
@@ -44,7 +44,7 @@ class Article extends Api
         $this->success(1,$info);
     }
 
-   
+
 
 
 }

+ 92 - 0
application/api/controller/Product.php

@@ -0,0 +1,92 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+use addons\epay\library\Service;
+/**
+ * 商品
+ */
+class Product extends Api
+{
+    protected $noNeedLogin = ['lists'];
+    protected $noNeedRight = ['*'];
+
+
+    public function lists()
+    {
+        $where = ['is_show'=>1];
+
+        $list = Db::name('product')->field('content',true)->where($where)->order('weigh desc')->autopage()->select();
+
+        $list = list_domain_image($list,['images']);
+
+        if(!empty($list)){
+            foreach($list as $key => &$item){
+                //第一个图
+                $item['image'] = isset($item['images'][0]) ? $item['images'][0] : '';
+            }
+        }
+
+        $this->success(1,$list);
+    }
+
+    public function info(){
+        $id = input('id',0);
+
+        $info = Db::name('product')->where('is_show',1)->where('id',$id)->find();
+        if(!$info){
+            $this->error('不存在的商品');
+        }
+        $info = info_domain_image($info,['images']);
+        //第一个图
+        $info['image'] = isset($info['images'][0]) ? $info['images'][0] : '';
+
+        $this->success(1,$info);
+    }
+
+    //兑换
+    public function buy(){
+        $remark = input('remark','');
+        $product_id = input('id',0);
+        $info = Db::name('product')->where('is_show',1)->where('id',$product_id)->find();
+        if(!$info){
+            $this->error('不存在的商品');
+        }
+
+        Db::startTrans();
+
+        //下单
+        $data = [
+            'order_no' => createUniqueNo('A',$this->auth->id),
+            'product_id' => $product_id,
+            'user_id'    => $this->auth->id,
+            'createtime' => time(),
+            'pay_fee' => $info['price'],
+            'remark' => $remark,
+            'status' => 0,
+        ];
+
+        $order_id = Db::name('order')->insertGetId($data);
+        if(!$order_id){
+            Db::rollback();
+            $this->error('兑换失败');
+        }
+
+        //扣钱
+        $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$info['price'],3,'积分兑换'.$info['title'],'order',$order_id);
+        if($rs_wallet['status'] == false){
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
+
+        Db::commit();
+        $this->success('兑换成功',$order_id);
+
+
+    }
+
+
+
+}

+ 3 - 3
application/common/library/Auth.php

@@ -26,7 +26,7 @@ class Auth
     //默认配置
     protected $config = [];
     protected $options = [];
-    protected $allowFields = ['id', 'username', 'nickname', 'avatar','mini_openid'];
+    protected $allowFields = ['id', 'username', 'nickname','mobile', 'avatar','mini_openid'];
 
     public function __construct($options = [])
     {
@@ -206,7 +206,7 @@ class Auth
             $this->_logined = true;
 
             //注册钱包
-//            Db::name('user_wallet')->insertGetId(['user_id'=>$user->id]);
+            Db::name('user_wallet')->insertGetId(['user_id'=>$user->id]);
 
             //注册成功的事件
             Hook::listen("user_register_successed", $this->_user, $data);
@@ -410,7 +410,7 @@ class Auth
 
         //追加
         $userinfo['avatar'] = one_domain_image($userinfo['avatar']);
-//        $userinfo['money'] = model('wallet')->getWallet($this->id,'money');
+        $userinfo['score'] = model('wallet')->getWallet($this->id,'score');
 
         return $userinfo;
     }

+ 1 - 1
application/common/model/Wallet.php

@@ -40,7 +40,7 @@ class Wallet extends Model
         //所有钱包余额
         $wallet = Db::name('user_wallet')->lock(true)->where(['user_id' => $user_id])->find();
         if(!$wallet) {
-            abort(500,'钱包余额获取失败');
+            abort(500,'余额获取失败');
         }
 
         if($wallet_name) { //返回指定钱包

+ 5 - 5
application/extra/wallet.php

@@ -4,13 +4,13 @@
  */
 return [
     'logtype' => [
-        1  => '后台充值',
-        2  => '扫码佣金',
-        3  => '关联佣金',
-        4  => '佣金提现',
+        1  => '后台增加',
+        2  => '后台减少',
+        3  => '兑换商品',
+        4  => '提现',
     ],
     'moneyname' => [
-        'money'    => '佣金',
+        'score'    => '积分',
     ],
 
 ];