123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <?php
- namespace app\api\controller;
- use app\admin\model\Customer;
- use app\admin\model\Third;
- use app\admin\model\Tzmoneylog;
- use app\admin\model\UserMoneyLog;
- use app\admin\model\UserMoneyRecharge;
- use app\admin\model\UserMoneyWithdrawal;
- use app\admin\model\Withdrawal;
- use app\common\controller\Api;
- use think\Db;
- use think\Exception;
- /**
- * 用户-我的钱包
- * @ApiWeigh (7)
- * @package app\api\controller
- */
- class UserMoney extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- /**
- * 用户余额
- * @ApiMethod (GET)
- * @ApiReturnParams (name="money", type="int", required=true, description="余额")
- * @ApiReturnParams (name="u_wmoney", type="string", required=true, description="累积提现")
- * @ApiReturnParams (name="u_cmoney", type="string", required=true, description="累积充值")
- * @ApiReturn ({"code":1,"msg":"用户余额","time":"1674894846","data":{"money":"985.50","u_wmoney":"0.00","u_cmoney":"0.00","prevtime_text":"","logintime_text":"","jointime_text":""}})
- */
- public function user_money()
- {
- $user_model = new \app\admin\model\User();
- $tanzghu = $user_model->where('id', $this->auth->id)->field('money,u_wmoney,u_cmoney')->find();
- $this->success('用户余额', $tanzghu);
- }
- /**
- * 余额明细记录
- * @ApiMethod (GET)
- * @ApiParams (name="type",type="int", required=false,description="变动类型:1=消费记录;2=充值明细;3=提现明细")
- * @ApiParams (name=limit,type="int", required=false,description="每页数量")
- * @ApiParams (name=page,type="int", required=false,description="页数")
- * @ApiReturnParams (name="money", type="int", required=true, description="变更余额")
- * @ApiReturnParams (name="before", type="string", required=true, description="变更前余额")
- * @ApiReturnParams (name="after", type="string", required=true, description="变更后余额")
- * @ApiReturnParams (name="memo", type="string", required=true, description="内容")
- * @ApiReturnParams (name="createtime", type="int", required=true, description="时间")
- * @ApiReturn ({"code":1,"msg":"余额明细记录","time":"1674896309","data":{"total":9,"per_page":"1","current_page":1,"last_page":9,"data":[{"id":9,"user_id":3,"money":"0.50","before":"985.00","after":"985.50","memo":"余额退款","createtime":1673229429,"type":1}]}})
- */
- public function money_log()
- {
- $type = input('type', 1);
- $page = input('page', 1);
- $limit = input('limit');
- $money_log_model = new UserMoneyLog();
- $list = $money_log_model->where(['user_id' => $this->auth->id, 'type' => $type])->order('id', 'desc')->paginate($limit, false, ['page' => $page]);
- $this->success('余额明细记录', $list);
- }
- /**
- * 提现
- * @ApiMethod (POST)
- * @ApiParams (name="money",type="float", required=true,description="提现金额")
- * @ApiParams (name="type",type="int", required=true,description="提现类型:1=微信,2=支付宝")
- */
- public function user_withdrawal()
- {
- $withdrawal_model = new UserMoneyWithdrawal();
- $third_model = new Third();
- $money_log_model = new UserMoneyLog();
- $money = $this->request->post('money', 0);
- if ($money < 100) {
- $this->error('最低提现金额为100');
- }
- if ($this->auth->money < $money) {
- $this->error('用户可用余额不足');
- }
- $type = $this->request->post('type');
- //微信提现
- if ($type == 1) {
- $openID = $third_model->where('user_id', $this->auth->id)->where('platform','xcc')->value('openid');
- $data = [
- 'type' => $type,
- 'openid' => $openID,
- 'money' => $money,
- 'user_id' => $this->auth->id,
- 'user_name' => $this->auth->username,
- 'create_time' => time(),
- 'status' => 1
- ];
- } else {
- $data = [
- 'type' => $type,
- 'z_name' => $this->auth->z_name,
- 'z_phone' => $this->auth->z_phone,
- 'money' => $money,
- 'user_id' => $this->auth->id,
- 'user_name' => $this->auth->username,
- 'create_time' => time(),
- 'status' => 1
- ];
- }
- Db::startTrans();
- try {
- $user = $this->auth->getUser();
- $money_log = [
- 'user_id' => $this->auth->id,
- 'type' => 3,
- 'memo' => '余额提现',
- 'money' => $money,
- 'before' => $user->money,
- 'after' => $user->money - $money,
- 'createtime' => time(),
- ];
- $user->money -= $money;
- $user->save();
- $withdrawal_model->insert($data);
- $money_log_model->insert($money_log);
- Db::commit();
- $this->success('提现申请已提交');
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e);
- }
- }
- /**
- * 充值
- * @ApiMethod (POST)
- * @ApiParams (name="money",type="float", required=true,description="提现金额")
- * @ApiParams (name="type",type="string", required=true,description="充值类型:wechat=微信,alipay=支付宝")
- * @ApiParams (name="mod",type="string", required=true,description="支付方法:web、wap、app、scan、pos、mp、miniapp")
- */
- public function user_recharge()
- {
- $money = $this->request->post('money', 0);
- if ($money < 1) {
- $this->error('最低充值金额为1');
- }
- $type = $this->request->post('type');
- if ($type != 'wechat' && $type != 'alipay') {
- $this->error('请选择支付类型');
- }
- $method = $this->request->post('mod');
- // 订单号
- $orderid = 'CZ' . order_no_s($this->auth->id);
- $recharge_model = new UserMoneyRecharge();
- Db::startTrans();
- try {
- $recharge_data = [
- 'user_id' => $this->auth->id,
- 'type' => $type,
- 'method' => $method,
- 'money' => $money,
- 'order_sn' => $orderid,
- 'create_time' => time(),
- ];
- $recharge_model->insert($recharge_data);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- $this->error($e);
- }
- $openID = '';
- if($type=='wechat'){
- $third_model = new Third();
- $openID = $third_model->where('user_id', $this->auth->id)->where('platform','xcc')->value('openid');
- }
- $params = [
- 'amount' => $money,
- 'orderid' => $orderid,
- 'type' => $type,
- 'title' => "用户充值",
- 'notifyurl' => common_url() . '/index.php/api/Notify/user_recharge_notify/type/' . $type,
- 'returnurl' => common_url() . '/index.php/api/Notify/user_recharge_notify/type/' . $type . '/out_trade_no/' . $orderid,
- 'method' => $method,
- 'openid' => $openID,
- ];
- $pay = \addons\epay\library\Service::submitOrder($params);
- $this->success('ok', $pay);
- }
- }
|