model = new \app\admin\model\FcOrder; $this->view->assign("statusList", $this->model->getStatusList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 订单退款 */ public function refund() { $ids = $this->request->post('ids'); $amount = (float)$this->request->post('amount'); $reason = $this->request->post('reason', ''); if ($amount <= 0) { $this->error('退款金额需大于 0'); } $ids = is_array($ids) ? $ids : explode(',', (string)$ids); $ids = array_filter($ids); if (!$ids) { $this->error('请选择要退款的订单'); } $orders = Db::name('fc_order')->where('id', 'in', $ids)->select(); if (!$orders) { $this->error('订单不存在'); } foreach ($orders as $order) { Db::name('fc_order')->where('id', $order['id'])->update([ 'status' => 'refunded', 'refund_amount' => $amount, 'refund_reason' => $reason, 'updatetime' => time(), ]); Db::name('fc_message')->insert([ 'user_id' => $order['user_id'], 'type' => 'system', 'title' => '订单退款', 'content' => '您的订单「' . $order['order_no'] . '」已退款' . $amount . '元' . ($reason ? ',原因:' . $reason : ''), 'isread' => 0, 'createtime' => time(), ]); } $this->success('退款成功'); } /** * 订单补单 */ public function supplement() { $orderNo = $this->request->post('orderNo'); if (trim((string)$orderNo) === '') { $this->error('订单号不能为空'); } $order = Db::name('fc_order')->where('order_no', $orderNo)->find(); if (!$order) { $this->error('订单不存在'); } if ($order['status'] === 'paid') { $this->success('订单已支付'); } Db::name('fc_order')->where('id', $order['id'])->update([ 'status' => 'paid', 'paytime' => time(), 'updatetime' => time(), ]); Db::name('fc_finance_flow')->insert([ 'flow_no' => 'SK' . date('YmdHis') . $order['id'], 'type' => 'income', 'scene' => '订单补单', 'amount' => $order['amount'], 'balance' => 0, 'related_id' => $order['id'], 'remark' => '订单补单', 'createtime' => time(), ]); $this->success('补单成功'); } }