Dianfei.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace app\admin\controller\xzdata;
  3. use alipay\AopCertClient;
  4. use alipay\request\AlipayFundTransUniTransferRequest;
  5. use app\common\model\MoneyLog;
  6. use app\common\model\ScoreLog;
  7. //use app\admin\model\UpgradeLog;
  8. use app\common\model\ScoreLogModel;
  9. use app\common\model\ThirdxzDforderModel;
  10. use app\common\model\ThirdxzHforderModel;
  11. use app\common\model\User as UserModel;
  12. use app\common\model\UserData;
  13. use app\admin\traits\Curd;
  14. use app\common\constants\AdminConstant;
  15. use app\common\controller\AdminController;
  16. use app\common\model\UserMoneyModel;
  17. use app\Request;
  18. use EasyAdmin\tool\CommonTool;
  19. use jianyan\excel\Excel;
  20. use think\App;
  21. use think\facade\Db;
  22. class Dianfei extends AdminController
  23. {
  24. public function __construct (App $app)
  25. {
  26. parent::__construct($app);
  27. $this->model = new ThirdxzDforderModel();
  28. }
  29. use Curd;
  30. /**
  31. * 充值列表
  32. * @return mixed|\think\response\Json
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. */
  37. public function index ()
  38. {
  39. if ($this->request->isAjax()) {
  40. if (input('selectFields')) {
  41. return $this->selectList();
  42. }
  43. list($page, $limit, $where) = $this->buildTableParames();
  44. if (($pid = $this->request->param('pid')) !== false && $pid)
  45. $where[] = ['pid', '=', $this->request->param('pid', '')];
  46. // if (($create_time = $this->request->param('create_time')) !== false && $create_time)
  47. // $where[] = ['create_time','in', explode(' - ', $create_time)];
  48. foreach ($where as $key=>&$val){
  49. if ($val[0] == 'create_time'){
  50. $val[2] = sr_getcurtime($val[2]);
  51. }
  52. }
  53. // sr_log(json_encode($where));
  54. $count = $this->model
  55. // ->withJoin('userData', 'INNER')
  56. ->where($where)
  57. ->where($this->user_map)
  58. ->count();
  59. $list = $this->model
  60. // ->withJoin('userData', 'INNER')
  61. ->where($where)
  62. ->where($this->user_map)
  63. ->withAttr('type', function ($val, $data){
  64. return ($val==1?'移动':($val==2?'联通':'电信'));
  65. })
  66. ->page($page, $limit)
  67. ->order($this->sort)
  68. ->select();
  69. $data = [
  70. 'code' => 0,
  71. 'msg' => Db::getLastSql(),
  72. 'count' => $count,
  73. 'data' => $list,
  74. ];
  75. return json($data);
  76. }
  77. return $this->fetch();
  78. }
  79. /**
  80. * 执行提现
  81. * @param $id
  82. * @throws \think\db\exception\DataNotFoundException
  83. * @throws \think\db\exception\DbException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. */
  86. public function czsuccess ($id)
  87. {
  88. $info = $this->model->where('id', $id)->where('status', 1)->find();
  89. if (empty($info))
  90. $this->error('充值记录状态或已充值');
  91. $user = Db::name('user')->findOrEmpty(['id' => $info['uid']]);
  92. if (empty($user) || $user['status'] != 1)
  93. $this->error('用户不存在或已被禁用');
  94. if ($user['is_auth'] != 1)
  95. $this->error('该用户还未实名认证');
  96. $this->model->where('id', $id)->save(['status'=>2]);
  97. $this->success('充值成功');
  98. }
  99. /**
  100. * 充值失败
  101. * @return mixed
  102. */
  103. public function czerror ()
  104. {
  105. if ($this->request->isPost()) {
  106. $post = $this->request->post();
  107. $order_info = $this->model->where('id', $post['id'])->findOrEmpty();
  108. $is_backsx = $post['is_backsx'];
  109. $error_text = $post['error_text'];
  110. empty($order_info) && $this->error('信息不存在');
  111. if ($order_info['status'] != 1){
  112. $this->error('状态错误,请刷新数据');
  113. }
  114. $this->model->startTrans();
  115. try {
  116. $this->model->where('id', $post['id'])->save(['status'=>3,'error_text'=>$error_text, 'is_backsx'=>$is_backsx]);
  117. if ($is_backsx == 1){
  118. edit_user_xz(18, $order_info['uid'], $order_info['xz_num']+$order_info['shouxu'], $order_info['hf_ordersn'], $order_info['shouxu']);
  119. edit_user_couponnum(6, $order_info['uid'], $order_info['price']/10);
  120. }else{
  121. edit_user_xz(18, $order_info['uid'], $order_info['xz_num'], $order_info['hf_ordersn'], 0);
  122. edit_user_couponnum(6, $order_info['uid'], $order_info['price']/10);
  123. }
  124. $this->model->commit();
  125. } catch (\Exception $e) {
  126. $this->model->rollback();
  127. $this->error('失败'.$e->getMessage());
  128. }
  129. $this->success('成功');
  130. }
  131. return $this->fetch();
  132. }
  133. /**
  134. * 增加余额
  135. * @return mixed
  136. */
  137. public function editmoney ()
  138. {
  139. if ($this->request->isPost()) {
  140. $post = $this->request->post();
  141. $user = $this->model->findOrEmpty(['id' => $post['uid']]);
  142. $money = $post['money'];
  143. $type = $post['type'];
  144. empty($user) && $this->error('用户不存在');
  145. $this->model->startTrans();
  146. try {
  147. if ($type == 'more'){
  148. edit_user_money(7, $post['uid'], $money);
  149. }else {
  150. edit_user_money(8, $post['uid'], $money);
  151. }
  152. $this->model->commit();
  153. } catch (\Exception $e) {
  154. $this->model->rollback();
  155. $this->error('失败'.$e->getMessage());
  156. }
  157. $this->success('成功');
  158. }
  159. return $this->fetch();
  160. }
  161. }