123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- namespace app\api\controller;
- use think\Controller;
- use think\Db;
- /**
- * @title 余额
- * Class Crystal
- * @controller Crystal
- * @group base
- */
- class Crystal extends Base
- {
- public function initialize()
- {
- parent::check_login();
- }
- /**
- * @title 余额充值(立即充值)
- * @desc 余额充值
- * @author qc
- * @url /api/Crystal/crystalRecharge
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:crystal type:int require:1 default:-- desc:充值数量
- * @return name:config type:array default:0 desc:支付配置
- * @return name:config.appId type:string default:-- desc:公众账号ID
- * @return name:config.nonceStr type:string default:-- desc:随机字符串
- * @return name:config.signType type:string default:-- desc:签名类型
- * @return name:config.paySign type:string default:-- desc:签名
- * @return name:config.timestamp type:string default:-- desc:时间戳
- */
- public function crystalRecharge()
- {
- $crystal = input('post.crystal',0);
- $price_total = $crystal;
- if($price_total <=0 ) $this->error('充值数量有误!');
- $crystal_order = [
- 'uid' => $this->uid ,
- 'crystal' => $crystal ,
- 'price_total' => $price_total,
- 'order_no' =>get_order_sn(),
- 'pay_no' =>get_order_sn(),
- 'create_at' => date("Y-m-d H:i:s")
- ];
- Db::startTrans();
- $config = false;$msg= '';
- try{
- $user_info = Db::table('store_member')->find($this->uid);
- Db::table('crystal_order')->insert($crystal_order);
- $notify_url = $this->request->root(true) . '/api/Pay/crystalRecharge';
- $pay_no = $crystal_order['pay_no'] ? $crystal_order['pay_no'] : get_order_sn();
- $crystal_order['price_total'] = 0.01;
- $config = Pay::wxPay('订单支付',$pay_no,$crystal_order['price_total'],$notify_url,'JSAPI',$user_info['openid']);
- if($config){
- Db::commit();
- }else{
- Db::rollback();
- }
- }catch (\Exception $e){
- Db::rollback();
- $msg = $e->getMessage();
- }
- if($config){
- $this->success('ok',['config'=>$config]);
- }else{
- $this->error($msg);
- }
- }
- /**
- * @title 删除订单
- * @desc 删除订单
- * @author qc
- * @url /api/Crystal/delCrystalOrder
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:order_id type:int require:1 default:-- desc:订单id
- */
- public function delCrystalOrder()
- {
- Db::table('crystal_order')->where(['uid'=>$this->uid,'id'=>input('post.order_id')])->delete();
- $this->success('ok');
- }
- /**
- * @title 获取余额充值订单列表
- * @desc 获取余额充值订单列表
- * @author qc
- * @url /api/Crystal/getCrystalOrderList
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int : default:1 desc:页数
- * @param name:page_num type:int : default:20 desc:每页数
- * @param name:status type:int : default:-1 desc:订单状态(-1全部,0待支付,1已支付)
- * @return name:order_no type:string default:-- desc:订单号
- * @return name:price_total type:string default:-- desc:支付金额
- * @return name:crystal type:string default:-- desc:充值余额数量
- * @return name:pay_state type:string default:-- desc:支付状态(0未支付,1已支付)
- * @return name:pay_at type:string default:-- desc:支付时间
- * @return name:pay_no type:string default:-- desc:支付单号
- */
- public function getCrystalOrderList()
- {
- $status = input('status',-1);
- $where=[];
- if($status > -1) $where['status'] = $status;
- $where['uid'] = $this->uid;
- $list = Db::table('crystal_order')
- ->where($where)
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取余额明细
- * @desc 获取余额明细
- * @author qc
- * @url /api/Crystal/getBalanceLog
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int : default:1 desc:页数
- * @param name:page_num type:int : default:20 desc:每页数
- * @return name:desc type:string default:-- desc:描述
- * @return name:type type:int default:-- desc:类型
- * @return name:balance type:int default:-- desc:余额变更数
- * @return name:create_at type:string default:-- desc:时间
- */
- public function getBalanceLog()
- {
- $list = Db::table('balance_info')
- ->field('id,desc,balance,type,create_at')
- ->where(['user_id'=>$this->uid])
- ->order('id desc')
- ->limit($this->page,$this->page_num)
- ->select();
- $this->success('ok',$list);
- }
- /**
- * @title 获取明信片明细
- * @desc 获取明信片明细
- * @author qc
- * @url /api/Crystal/getCrystalLog
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int : default:1 desc:页数
- * @param name:page_num type:int : default:20 desc:每页数
- * @return name:desc type:string default:-- desc:描述
- * @return name:type type:int default:-- desc:类型
- * @return name:crystal type:int default:-- desc:明信片变更数
- * @return name:create_at type:string default:-- desc:时间
- */
- public function getCrystalLog()
- {
- $list = Db::table('crystal_info')
- ->field('id,desc,crystal,type,create_at')
- ->where(['user_id'=>$this->uid])
- ->order('id desc')
- ->limit($this->page,$this->page_num)
- ->select();
- $this->success('ok',$list);
- }
- }
|