作者 王智

xiugao

@@ -2,9 +2,12 @@ @@ -2,9 +2,12 @@
2 2
3 namespace app\admin\controller; 3 namespace app\admin\controller;
4 4
  5 +use EasyWeChat\Foundation\Application;
5 use think\Db; 6 use think\Db;
6 use app\api\controller\GuanYiCloud; 7 use app\api\controller\GuanYiCloud;
7 use app\common\controller\Backend; 8 use app\common\controller\Backend;
  9 +use think\exception\PDOException;
  10 +use think\exception\ValidateException;
8 11
9 /** 12 /**
10 * 订单管理 13 * 订单管理
@@ -102,4 +105,83 @@ class Order extends Backend @@ -102,4 +105,83 @@ class Order extends Backend
102 $this->success('无更新'); 105 $this->success('无更新');
103 } 106 }
104 } 107 }
  108 +
  109 +
  110 + /**
  111 + * 编辑
  112 + */
  113 + public function edit($ids = null)
  114 + {
  115 + $row = $this->model->get($ids);
  116 + if (!$row) {
  117 + $this->error(__('No Results were found'));
  118 + }
  119 + $adminIds = $this->getDataLimitAdminIds();
  120 + if (is_array($adminIds)) {
  121 + if (!in_array($row[$this->dataLimitField], $adminIds)) {
  122 + $this->error(__('You have no permission'));
  123 + }
  124 + }
  125 + if ($this->request->isPost()) {
  126 + $params = $this->request->post("row/a");
  127 + if ($params) {
  128 + $params = $this->preExcludeFields($params);
  129 + $result = false;
  130 + Db::startTrans();
  131 + try {
  132 + //是否采用模型验证
  133 + if ($this->modelValidate) {
  134 + $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  135 + $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  136 + $row->validateFailException(true)->validate($validate);
  137 + }
  138 +
  139 + if ($params['status'] == 5) {
  140 + $PayOrderInfo = Db::name('pay_order')->where('OrderSn', $params['OrderSn'])->find();
  141 + //配置
  142 + $options = [
  143 + 'app_id' => 'wxf0764538543e66eb',
  144 + 'payment' => [
  145 + 'merchant_id' => '1604311610',
  146 + 'key' => 'nbusy93Hqwe6390LSs4k2Dap1nxZvqps',
  147 + 'cert_path' => '/home/wwwroot/fast/book/addons/epay/certs/apiclient_cert.pem', // XXX: 绝对路径!!!!
  148 + 'key_path' => '/home/wwwroot/fast/book/addons/epay/certs/apiclient_key.pem', // XXX: 绝对路径!!!!
  149 + ],
  150 + ];
  151 + $app = new Application($options);
  152 + $payment = $app->payment;
  153 + try {
  154 + $result = $payment->refundByTransactionId($PayOrderInfo['WeChatOrder'], $PayOrderInfo['PayOrder'], $PayOrderInfo['money'] * 100, $PayOrderInfo['money'] * 100); // 总金额 100, 退款 80,操作员:商户号
  155 + } catch (Exception $e) {
  156 + $e->getMessage();
  157 + }
  158 + if (!$result) {
  159 + $this->error('退款失败', 0);
  160 + die;
  161 + }
  162 + }
  163 + $result = $row->allowField(true)->save($params);
  164 + Db::commit();
  165 + } catch (ValidateException $e) {
  166 + Db::rollback();
  167 + $this->error($e->getMessage());
  168 + } catch (PDOException $e) {
  169 + Db::rollback();
  170 + $this->error($e->getMessage());
  171 + } catch (Exception $e) {
  172 + Db::rollback();
  173 + $this->error($e->getMessage());
  174 + }
  175 + if ($result !== false) {
  176 + $this->success();
  177 + } else {
  178 + $this->error(__('No rows were updated'));
  179 + }
  180 + }
  181 + $this->error(__('Parameter %s can not be empty', ''));
  182 + }
  183 + $this->view->assign("row", $row);
  184 + return $this->view->fetch();
  185 + }
  186 +
105 } 187 }