Crystal.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace app\api\controller;
  3. use think\Controller;
  4. use think\Db;
  5. /**
  6. * @title 元石
  7. * Class Crystal
  8. * @controller Crystal
  9. * @group base
  10. */
  11. class Crystal extends Base
  12. {
  13. public function initialize()
  14. {
  15. parent::check_login();
  16. }
  17. /**
  18. * @title 元石充值(立即充值)
  19. * @desc 元石充值
  20. * @author qc
  21. * @url /api/Crystal/crystalRecharge
  22. * @method POST
  23. * @header name:Authorization require:1 desc:Token
  24. * @param name:crystal type:int require:1 default:-- desc:充值数量
  25. * @return name:config type:array default:0 desc:支付配置
  26. * @return name:config.appId type:string default:-- desc:公众账号ID
  27. * @return name:config.nonceStr type:string default:-- desc:随机字符串
  28. * @return name:config.signType type:string default:-- desc:签名类型
  29. * @return name:config.paySign type:string default:-- desc:签名
  30. * @return name:config.timestamp type:string default:-- desc:时间戳
  31. */
  32. public function crystalRecharge()
  33. {
  34. $crystal = input('post.crystal',0);
  35. $price_total = $crystal;
  36. if($crystal <=0) $this->error('充值数量有误!');
  37. Db::startTrans();
  38. $config = false;$msg= '';
  39. try{
  40. $user_info = Db::table('store_member')->find($this->uid);
  41. $crystal_order = [
  42. 'uid' => $this->uid ,
  43. 'crystal' => $crystal ,
  44. 'price_total' => $price_total,
  45. 'order_no' =>get_order_sn(),
  46. 'pay_no' =>get_order_sn(),
  47. 'create_at' => date("Y-m-d H:i:s")
  48. ];
  49. Db::table('crystal_order')->insert($crystal_order);
  50. $notify_url = $this->request->root(true) . '/api/Pay/crystalRecharge';
  51. $config = Pay::wxPay('订单支付',$crystal_order['pay_no'],$crystal_order['price_total'],$notify_url,'JSAPI',$user_info['openid']);
  52. if($config){
  53. Db::commit();
  54. }else{
  55. Db::rollback();
  56. $msg='获取支付配置失败!';
  57. }
  58. }catch (\Exception $e){
  59. Db::rollback();
  60. $msg = $e->getMessage();
  61. }
  62. if($config){
  63. $this->success('ok',['config'=>$config]);
  64. }else{
  65. $this->error($msg);
  66. }
  67. }
  68. /**
  69. * @title 删除订单
  70. * @desc 删除订单
  71. * @author qc
  72. * @url /api/Crystal/delCrystalOrder
  73. * @method POST
  74. * @header name:Authorization require:1 desc:Token
  75. * @param name:order_id type:int require:1 default:-- desc:订单id
  76. */
  77. public function delCrystalOrder()
  78. {
  79. Db::table('crystal_order')->where(['uid'=>$this->uid,'id'=>input('post.order_id')])->delete();
  80. $this->success('ok');
  81. }
  82. /**
  83. * @title 获取元石充值订单列表
  84. * @desc 获取元石充值订单列表
  85. * @author qc
  86. * @url /api/Crystal/getCrystalOrderList
  87. * @method GET
  88. * @header name:Authorization require:1 desc:Token
  89. * @param name:page type:int : default:1 desc:页数
  90. * @param name:page_num type:int : default:20 desc:每页数
  91. * @param name:status type:int : default:-1 desc:订单状态(-1全部,0待支付,1已支付)
  92. * @return name:order_no type:string default:-- desc:订单号
  93. * @return name:price_total type:string default:-- desc:支付金额
  94. * @return name:crystal type:string default:-- desc:充值元石数量
  95. * @return name:pay_state type:string default:-- desc:支付状态(0未支付,1已支付)
  96. * @return name:pay_at type:string default:-- desc:支付时间
  97. * @return name:pay_no type:string default:-- desc:支付单号
  98. */
  99. public function getCrystalOrderList()
  100. {
  101. $status = input('status',-1);
  102. $where=[];
  103. if($status > -1) $where['status'] = $status;
  104. $where['uid'] = $this->uid;
  105. $list = Db::table('crystal_order')
  106. ->where($where)
  107. ->order('id desc')
  108. ->limit($this->off_set,$this->page_num)
  109. ->select();
  110. $this->success('ok',['list'=>$list]);
  111. }
  112. /**
  113. * @title 获取元石变更日志
  114. * @desc 获取元石变更日志
  115. * @author qc
  116. * @url /api/Crystal/getCrystalLog
  117. * @method GET
  118. * @header name:Authorization require:1 desc:Token
  119. * @param name:page type:int default:1 desc:页数
  120. * @param name:page_num type:int default:20 desc:每页数
  121. * @return name:create_at type:string default:-- desc:时间
  122. * @return name:crystal type:int default:-- desc:变更数
  123. * @return name:desc type:string default:-- desc:描述
  124. */
  125. public function getCrystalLog()
  126. {
  127. $list = Db::table('crystal_info')
  128. ->field('id,create_at,crystal,desc')
  129. ->where(['user_id'=>$this->uid,'is_deleted'=>0])
  130. ->order('id desc')
  131. ->limit($this->off_set,$this->page_num)
  132. ->select();
  133. $this->success('ok',['list'=>$list]);
  134. }
  135. }