huazhiyu
lqmac 1 year ago
parent f8ca21913e
commit 85777c314e
  1. 6
      application/admin/model/user/Withdraw.php
  2. 35
      application/api/controller/User.php
  3. 53
      application/common/service/OrderService.php

@ -16,11 +16,11 @@ class Withdraw extends Model
protected $name = 'user_withdraw';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $deleteTime = false;
// 追加属性

@ -16,6 +16,7 @@ use app\admin\model\Warehouse;
use EasyWeChat\Factory;
use think\Db;
use app\admin\model\user\Recharge;
use app\admin\model\user\Withdraw;
/**
* 会员接口
@ -699,6 +700,40 @@ class User extends Api
$this->success("succ");
}
/**
* 充值
* [recharge description]
* @return [type] [description]
*/
public function withdraw(){
$user = $this->auth->getUserinfo();
$method = $this->request->post("method", "wechat");
$amount = $this->request->post("amount", 0);
$inData = [
"user_id" => $user['id'],
"method" => $method,
"amount" => $amount,
];
Withdraw::create($inData);
$this->success("succ");
}
public function withdrawList(){
$page = $this->request->post("page", 1);
$limit = $this->request->post("limit", 10);
$status = $this->request->post("status", 1);
$list = Withdraw::where('user_id', $this->auth->id)->order('id', 'desc')->paginate($this->request->param('list_rows', $limit))->each(function ($item, $key){
// $user = UserModel::where('id', $item['child_id'])->field('username,nickname,avatar')->find();
// $item['jointime'] = date("Y-m-d H:i:s", $item['createtime']);
// $item['username'] = $user['username'] ?? "";
// $item['nickname'] = $user['nickname'] ?? "";
// $item['avatar'] = cdnurl($user['avatar'] ?? "", true);
// $item['total_commission_amount'] = $item['amount'];
return $item;
});
$this->success("succ", $list);
}

@ -0,0 +1,53 @@
<?php
namespace app\common\service;
use think\Cache;
use think\Model;
use app\common\model\User;
use app\admin\model\transaction\Record;
/**
* 订单服务服务
*/
class OrderService
{
/**
* 用户佣金变化
* [userCommission description]
* @param [type] $type [description]
* @param [type] $user [description]
* @param [type] $item_id [description]
* @param [type] $amount [description]
* @return [type] [description]
*/
public function userCommission($type, $user, $item_id, $amount){
$pidUser = User::where('id', $user['pid'])->find();
if (!$pidUser) {
return false;
}
$inData = [
'user_id' => $pidUser['id'],
'child_id' => $user['id'],
'item_id' => $item_id,
'amount' => $amount,
'type' => $type,
];
$ret = Record::create($inData);
if ($ret === false) {
return false;
}
$userData = [
"available_commission_amount" => $pidUser['available_commission_amount'] + $amount,
"updatetime" => time(),
];
if (in_array($type, [0,1])) {
$userData['total_commission_amount'] = $pidUser['total_commission_amount'] + $amount;
}
$ret = User::where('id', $pidUser['id'])->update($userData);
return $ret;
}
}
Loading…
Cancel
Save