model = new \app\admin\model\Goodorder; $this->view->assign("statusList", $this->model->getStatusList()); } /** * 默认生成的控制器所继承的父类中有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(['username']); } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } public function refund() { $ids = input('ids'); $row = $this->model->get($ids); if(!empty($row)){ $row = $row->toArray(); } //提交验证 if (!$row) { $this->error(__('No Results were found')); } if (!$this->auth->id) { $this->error(__('You have no permission')); } if ($this->request->isPost()) { $params = $this->request->post('row/a'); if($params['status']==1) { //必要配置 $config = [ 'app_id' => 'wxdc450b7c5d0a0f80', 'mch_id' => '1635096198', 'key' => 'e3NkU3L7vmz84H92kfKT5d9qBCOmvdEB', // API v2 密钥 (注意: 是v2密钥 是v2密钥 是v2密钥) 'cert_path' => ROOT_PATH.'public/cert/apiclient_cert.pem', // XXX: 绝对路径!!!! 'key_path' => ROOT_PATH.'public/cert/apiclient_key.pem', // XXX: 绝对路径!!! 'notify_url' => common_url() . '/api/Notice/tableware_notify', // 你也可以在下单时单独设置来想覆盖它 ]; $app = Factory::payment($config); $refund_no = 'TK' . pay_no(999); $result = $app->refund->byOutTradeNumber($row['pay_no'], $refund_no, $row['total'], $params['refund_money'], [ // 可在此处传入其他参数,详细参数见微信支付文档 'refund_desc' => '退款', ]); // if($result['return_code']=='FAIL'){ // $this->error($result['err_code_des'],'index'); // } if($result['result_code']=='FAIL'){ $this->error($result['err_code_des'],'index'); } print_r($result);die; $this->model->save(['status'=>7],['id'=>$ids]); $this->success('退款成功', 'index'); } else{ $this->model->save(['status'=>3],['id'=>$ids]); $this->success('退款驳回','index'); } } // print_r($row);die; $this->view->assign("row", $row); return $this->view->fetch('refund'); } }