model = new \app\admin\model\RecharOrder; $this->view->assign("statusList", $this->model->getStatusList()); $this->view->assign("payTypeList", $this->model->getPayTypeList()); $this->view->assign("platformList", $this->model->getPlatformList()); } public function import() { parent::import(); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->with(['user']) ->where($where) ->order($sort, $order) ->paginate($limit); foreach ($list as $row) { $row->getRelation('user')->visible(['nickname']); } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } /** * 退款 */ public function refund($ids = null) { $result = [ 'code' => 1, 'msg' => '操作成功', ]; Db::startTrans(); try { $row = $this->model->get($ids); if (!$row) { throw new Exception(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { throw new Exception(__('You have no permission')); } } if ($row['status'] != 1) { throw new Exception('支付成功才能退款'); } if ($row['refund_money'] != 0) { throw new Exception('已退款'); } //验证用户钻石是否足够 $userWhere['id'] = $row['user_id']; $user = model('User')->where($userWhere)->lock(true)->find(); $userJewel = isset($user['jewel']) ? $user['jewel'] : 0; if ($userJewel < $row['jewel']) { throw new Exception('钻石不足,无法退款'); } //更新退款金额 $data = [ 'refund_money' => $row['money'],//退款金额 'status' => 2,//订单状态:-1=支付超时,0=支付中,1=支付成功,2=退款 ]; $where['id'] = $ids; $res = $this->model->update($data,$where); if (!$res) { throw new Exception('更新退款金额失败'); } //记录退款日志 $res = model('Wallet')->lockChangeAccountRemain($row['user_id'],$row['jewel'],'-',$user['jewel'],'充值退款',18,'jewel'); if (!$res['status']) { throw new Exception($res['msg']); } //实际退款 $refundParams = [ 'order' => [ 'pay_out_trade_no' => $row['order_no'], 'pay_fee' => $row['money'], 'pay_type' => $row['pay_type'], ], 'table' => 'rechar_order', 'table_id' => $ids, 'refund_price' => $row['money'], 'remark' => '充值退款', ]; /*$refundParams['order']['pay_fee'] = 0.01; $refundParams['refund_price'] = 0.01;*/ $refundRes = $this->model->old_refund($refundParams); if ($refundRes['status'] == 0) { throw new Exception($refundRes['msg']); } Db::commit(); } catch (Exception $e) { Db::rollback(); $result['code'] = 0; $result['msg'] = $e->getMessage(); } return json($result); } }