diff --git a/application/admin/model/user/Withdraw.php b/application/admin/model/user/Withdraw.php index 7bb53a6..031b8a1 100644 --- a/application/admin/model/user/Withdraw.php +++ b/application/admin/model/user/Withdraw.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; // 追加属性 diff --git a/application/api/controller/User.php b/application/api/controller/User.php index 7c8afab..cbe7497 100755 --- a/application/api/controller/User.php +++ b/application/api/controller/User.php @@ -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); + } + diff --git a/application/common/service/OrderService.php b/application/common/service/OrderService.php new file mode 100644 index 0000000..5aa6ce6 --- /dev/null +++ b/application/common/service/OrderService.php @@ -0,0 +1,53 @@ +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; + } + + +} \ No newline at end of file