Huafei.php 5.8 KB

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