model = new ThirdxzDforderModel(); } use Curd; /** * 充值列表 * @return mixed|\think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function index () { if ($this->request->isAjax()) { if (input('selectFields')) { return $this->selectList(); } list($page, $limit, $where) = $this->buildTableParames(); if (($pid = $this->request->param('pid')) !== false && $pid) $where[] = ['pid', '=', $this->request->param('pid', '')]; // if (($create_time = $this->request->param('create_time')) !== false && $create_time) // $where[] = ['create_time','in', explode(' - ', $create_time)]; foreach ($where as $key=>&$val){ if ($val[0] == 'create_time'){ $val[2] = sr_getcurtime($val[2]); } } // sr_log(json_encode($where)); $count = $this->model // ->withJoin('userData', 'INNER') ->where($where) ->where($this->user_map) ->count(); $list = $this->model // ->withJoin('userData', 'INNER') ->where($where) ->where($this->user_map) ->withAttr('type', function ($val, $data){ return ($val==1?'移动':($val==2?'联通':'电信')); }) ->page($page, $limit) ->order($this->sort) ->select(); $data = [ 'code' => 0, 'msg' => Db::getLastSql(), 'count' => $count, 'data' => $list, ]; return json($data); } return $this->fetch(); } /** * 执行提现 * @param $id * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function czsuccess ($id) { $info = $this->model->where('id', $id)->where('status', 1)->find(); if (empty($info)) $this->error('充值记录状态或已充值'); $user = Db::name('user')->findOrEmpty(['id' => $info['uid']]); if (empty($user) || $user['status'] != 1) $this->error('用户不存在或已被禁用'); if ($user['is_auth'] != 1) $this->error('该用户还未实名认证'); $this->model->where('id', $id)->save(['status'=>2]); $this->success('充值成功'); } /** * 充值失败 * @return mixed */ public function czerror () { if ($this->request->isPost()) { $post = $this->request->post(); $order_info = $this->model->where('id', $post['id'])->findOrEmpty(); $is_backsx = $post['is_backsx']; $error_text = $post['error_text']; empty($order_info) && $this->error('信息不存在'); if ($order_info['status'] != 1){ $this->error('状态错误,请刷新数据'); } $this->model->startTrans(); try { $this->model->where('id', $post['id'])->save(['status'=>3,'error_text'=>$error_text, 'is_backsx'=>$is_backsx]); if ($is_backsx == 1){ edit_user_xz(18, $order_info['uid'], $order_info['xz_num']+$order_info['shouxu'], $order_info['hf_ordersn'], $order_info['shouxu']); edit_user_couponnum(6, $order_info['uid'], $order_info['price']/10); }else{ edit_user_xz(18, $order_info['uid'], $order_info['xz_num'], $order_info['hf_ordersn'], 0); edit_user_couponnum(6, $order_info['uid'], $order_info['price']/10); } $this->model->commit(); } catch (\Exception $e) { $this->model->rollback(); $this->error('失败'.$e->getMessage()); } $this->success('成功'); } return $this->fetch(); } /** * 增加余额 * @return mixed */ public function editmoney () { if ($this->request->isPost()) { $post = $this->request->post(); $user = $this->model->findOrEmpty(['id' => $post['uid']]); $money = $post['money']; $type = $post['type']; empty($user) && $this->error('用户不存在'); $this->model->startTrans(); try { if ($type == 'more'){ edit_user_money(7, $post['uid'], $money); }else { edit_user_money(8, $post['uid'], $money); } $this->model->commit(); } catch (\Exception $e) { $this->model->rollback(); $this->error('失败'.$e->getMessage()); } $this->success('成功'); } return $this->fetch(); } }