123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- <?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/payOrder
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:o_id type:int require:1 default:-- desc:订单id
- * @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 payOrder()
- {
- $o_id = input('post.o_id',0);
- $crystal_order =Db::table('crystal_order')->find($o_id);
- $user_info = Db::table('store_member')->where('id',$this->uid)->find();
- if(!$user_info['openid']) $this->error('请先完善用户信息');
- if(empty($crystal_order) || $crystal_order['pay_state'] !=0 ) $this->error('订单有误');
- Db::startTrans();
- $config = false;$msg= '';
- try{
- $notify_url = $this->request->root(true) . '/api/Pay/crystalRecharge';
- $pay_no = $crystal_order['pay_no'] ? $crystal_order['pay_no'] : get_order_sn();
- $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/crystalRecharge
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:crystal type:int require:1 default:-- desc:充值数量
- * @param name:price_total 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 = input('post.price_total',0);
- if($crystal <=0 || $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")
- ];
- $user_info = Db::table('store_member')->find($this->uid);
- Db::startTrans();
- $config = false;$msg= '';
- try{
- 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();
- $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/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);
- }
- /**
- * @title 水晶提现申请
- * @desc 水晶提现申请
- * @author qc
- * @url /api/Crystal/crystalCash
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:crystal type:float : default:1 desc:提现额度
- * @return name:id type:int default:-- desc:提现记录id
- */
- public function crystalCash()
- {
- $crystal = input('post.crystal',0);
- $user_info = Db::table('store_member')->where('id',$this->uid)->find();
- if($user_info['crystal_cash'] < $crystal) $this->error('可提现水晶不足!');
- $data = [
- 'uid' => $this->uid,
- 'order_no' => get_order_sn(),
- 'price_total' => $crystal,
- 'crystal' => $crystal,
- 'sh_status' => 0,
- 'status' => 0,
- 'create_at' => date('Y-m-d H:i:s'),
- ];
- Db::table('crystal_cash_order')->insert($data);
- $id = Db::getLastInsID();
- Db::table('store_member')->where('id',$user_info['id'])->update(['crystal_cash'=>bcsub($user_info['crystal_cash'],$crystal,2)]);
- crystal_log($this->uid,$crystal*-1,'水晶提现',4,$id);
- $this->success('申请成功,等待审核',['id'=>$id]);
- }
- /**
- * @title 取消水晶提现申请
- * @desc 取消水晶提现申请
- * @author qc
- * @url /api/Crystal/cancelCrystalCash
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:float : default:1 desc:提现记录id
- */
- public function cancelCrystalCash()
- {
- $id = input('post.id',0);
- $app_info = Db::table('crystal_cash_order')->where('cancel_status',0)->where('id',$id)->find();
- if(empty($app_info)) $this->error('提现记录不存在!');
- $user_info = Db::table('store_member')->field('crystal_cash')->where('id',$this->uid)->find();
- Db::table('store_member')->where('id',$this->uid)->update(['crystal_cash'=>bcadd($user_info['crystal_cash'],$app_info['crystal'],2)]);
- crystal_log($this->uid,$app_info['crystal'],'提现取消',7,$id);
- $this->success('取消成功',['id'=>$id]);
- }
- /**
- * @title 获取水晶提现申请记录
- * @desc 获取水晶提现申请记录
- * @author qc
- * @url /api/Crystal/getCrystalCashLog
- * @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:sh_status type:int : default:-1 desc:审核状态
- * @return name:crystal type:int default:-- desc:提现额度
- * @return name:create_at type:string default:-- desc:时间
- * @return name:sh_status type:string default:-- desc:审核状态(0未审核1审核通过2审核不通过)
- * @return name:status type:string default:-- desc:处理状态0未完成1已完成
- */
- public function getCrystalCashLog()
- {
- $where = [];
- $where['user_id'] = $this->uid;
- $where['cancel_status'] = 0;
- $sh_status = input('get.sh_status',-1);
- if($sh_status >=0) $where['sh_status'] = $sh_status;
- $list = Db::table('crystal_cash_order')
- ->field('id,crystal,create_at,sh_status')
- ->where($where)
- ->order('id desc')
- ->limit($this->page,$this->page_num)
- ->select();
- $this->success('ok',['list'=>$list]);
- }
- }
|