作者 王智

xiugao

... ... @@ -2,9 +2,12 @@
namespace app\admin\controller;
use EasyWeChat\Foundation\Application;
use think\Db;
use app\api\controller\GuanYiCloud;
use app\common\controller\Backend;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 订单管理
... ... @@ -102,4 +105,83 @@ class Order extends Backend
$this->success('无更新');
}
}
/**
* 编辑
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException(true)->validate($validate);
}
if ($params['status'] == 5) {
$PayOrderInfo = Db::name('pay_order')->where('OrderSn', $params['OrderSn'])->find();
//配置
$options = [
'app_id' => 'wxf0764538543e66eb',
'payment' => [
'merchant_id' => '1604311610',
'key' => 'nbusy93Hqwe6390LSs4k2Dap1nxZvqps',
'cert_path' => '/home/wwwroot/fast/book/addons/epay/certs/apiclient_cert.pem', // XXX: 绝对路径!!!!
'key_path' => '/home/wwwroot/fast/book/addons/epay/certs/apiclient_key.pem', // XXX: 绝对路径!!!!
],
];
$app = new Application($options);
$payment = $app->payment;
try {
$result = $payment->refundByTransactionId($PayOrderInfo['WeChatOrder'], $PayOrderInfo['PayOrder'], $PayOrderInfo['money'] * 100, $PayOrderInfo['money'] * 100); // 总金额 100, 退款 80,操作员:商户号
} catch (Exception $e) {
$e->getMessage();
}
if (!$result) {
$this->error('退款失败', 0);
die;
}
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were updated'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
$this->view->assign("row", $row);
return $this->view->fetch();
}
}
... ...