Recharge.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Exception;
  6. class Recharge extends Api
  7. {
  8. protected $noNeedLogin = [];
  9. protected $noNeedRight = '*';
  10. //首页
  11. public function getList(){
  12. $where = [
  13. 'company_id' => $this->auth->company_id,
  14. 'status' => 1,
  15. ];
  16. $field = 'id,price,giftprice';
  17. $list = Db::name('recharge_config')->field($field)->where($where)->order('id desc')->select();
  18. //追加赠送
  19. if(!empty($list)){
  20. $config_ids = array_column($list,'id');
  21. $g = 'gift';
  22. $c = 'coupons';
  23. $gift = Db::name('recharge_gift')->alias($g)
  24. ->field($g.'.config_id,'.$g.'.coupon_id,'.$g.'.number,coupons.name,coupons.info,coupons.days')
  25. ->join($c,$c.'.id = '.$g.'.coupon_id' ,'LEFT')
  26. ->where($g.'.config_id','IN',$config_ids)
  27. ->where($c.'.status',1)
  28. ->select();
  29. foreach($list as $key => &$val){
  30. $val['gift'] = [];
  31. foreach($gift as $k => $v){
  32. if($val['id'] == $v['config_id']){
  33. unset($v['config_id']);
  34. $val['gift'][] = $v;
  35. }
  36. }
  37. }
  38. }
  39. $this->success(1,$list);
  40. }
  41. /**
  42. * 充值
  43. * @return void
  44. */
  45. /*public function add()
  46. {
  47. Db::startTrans();
  48. try {
  49. //验证参数
  50. $id = $this->request->param('id',0);
  51. $amounts = $this->request->param('amounts',0.00);
  52. if (empty($id) && empty($amounts)) {
  53. throw new Exception('参数错误');
  54. }
  55. if (!empty($id)) {
  56. } else {
  57. $isInt = is_int($amounts);
  58. if (!$isInt) {
  59. throw new Exception('请输入整数');
  60. }
  61. if ($amounts < 1) {
  62. throw new Exception('充值金额有误');
  63. }
  64. }
  65. $userId = $this->auth->id;
  66. $time = time();
  67. $data = [
  68. 'car_number' => $this->request->param('car_number', ''),
  69. 'car_model' => $this->request->param('car_model', ''),
  70. ];
  71. $data['user_id'] = $userId;
  72. $data['createtime'] = $time;
  73. $res = $this->model->insertGetId($data);
  74. if (!$res) {
  75. throw new Exception('操作失败');
  76. }
  77. Db::commit();
  78. $this->success('操作成功');
  79. } catch (Exception $e) {
  80. Db::rollback();
  81. $this->error($e->getMessage());
  82. }
  83. }*/
  84. }