瀏覽代碼

付费图片

lizhen_gitee 19 小時之前
父節點
當前提交
81ed8900a7
共有 1 個文件被更改,包括 107 次插入0 次删除
  1. 107 0
      application/api/controller/Orderimage.php

+ 107 - 0
application/api/controller/Orderimage.php

@@ -0,0 +1,107 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 消息收费图片订单
+ */
+class Orderimage extends Api
+{
+
+
+    // 无需登录的接口,*表示全部
+    protected $noNeedLogin = [];
+    // 无需鉴权的接口,*表示全部
+    protected $noNeedRight = ['*'];
+
+
+    public function create()
+    {
+        $price = input('price',0);
+        if($price <= 0){
+            $this->error('价格不能小于零');
+        }
+
+        $message_id = input('message_id','','trim');
+        $check = Db::name('order_image')->where('message_id',$message_id)->find();
+        if($check){
+            $this->error('消息重复');
+        }
+
+        $data = [
+            'user_id' => $this->auth->id,
+            'to_user_id' => input('to_user_id',0),
+            'message_id' => $message_id,
+            'image' => input('image',''),
+            'price' => $price,
+            'status' => 0,
+            'createtime' => time(),
+        ];
+
+        Db::name('order_image')->insertGetId($data);
+
+        $this->success(1);
+    }
+
+    public function pay(){
+        $message_id = input('message_id','','trim');
+
+        $order = Db::name('order_image')->where('message_id',$message_id)->where('to_user_id',$this->auth->id)->find();
+        if(!$order){
+            $this->error('没有找到付费信息');
+        }
+        if($order['status'] != 0){
+            $this->error('已经付费过了');
+        }
+
+        Db::startTrans();
+
+        if($order['price'] > 0){
+
+            //付钱
+            $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$order['user_id'],'gold',-$order['price'],111,'解锁付费图片','order_image',$order['id']);
+            if($wallet_rs['status'] === false){
+                Db::rollback();
+                $this->error($wallet_rs['msg']);
+            }
+
+            //收益
+            $money_to_gold = config('site.money_to_gold') ?: 10;
+            $money = bcdiv($order['price'],$money_to_gold,2);
+
+            //平台手续费
+            $platrate = config('site.order_image_platrate');
+            $plat_money = bcdiv(bcmul($money,$platrate,2),100,2);
+
+            //减去手续费,得收益金额
+            $shouyi = bcsub($money,$plat_money,2);
+
+            $wallet_rs = model('wallet')->lockChangeAccountRemain($order['user_id'],$this->auth->id,'money',$shouyi,112,'付费图片收益','order_image',$order['id'],2);
+            if($wallet_rs['status'] === false){
+                Db::rollback();
+                $this->error($wallet_rs['msg']);
+            }
+
+        }
+
+        $rs = Db::name('order_image')->where('id',$order['id'])->update([
+            'status'  => 1,
+            'paytime' => time(),
+
+            'platrate' => $platrate,
+            'platmoney' => $plat_money,
+            'shouyi' => $shouyi,
+        ]);
+        if($rs === false){
+            Db::rollback();
+            $this->error('付款失败');
+        }
+
+        Db::commit();
+        $this->success();
+
+    }
+
+}