123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?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($crystal <=0) $this->error('充值数量有误!');
- Db::startTrans();
- $config = false;$msg= '';
- try{
- $user_info = Db::table('store_member')->find($this->uid);
- $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::table('crystal_order')->insert($crystal_order);
- $notify_url = $this->request->root(true) . '/api/Pay/crystalRecharge';
- $config = Pay::wxPay('订单支付',$crystal_order['pay_no'],$crystal_order['price_total'],$notify_url,'JSAPI',$user_info['openid']);
- if($config){
- Db::commit();
- }else{
- Db::rollback();
- $msg='获取支付配置失败!';
- }
- }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/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:create_at type:string default:-- desc:时间
- * @return name:crystal type:int default:-- desc:变更数
- * @return name:desc type:string default:-- desc:描述
- */
- public function getCrystalLog()
- {
- $list = Db::table('crystal_info')
- ->field('id,create_at,crystal,desc')
- ->where(['user_id'=>$this->uid,'is_deleted'=>0])
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- $this->success('ok',['list'=>$list]);
- }
- }
|