diff --git a/application/admin/controller/ReceiptOrder.php b/application/admin/controller/ReceiptOrder.php index af08c18..0a99759 100755 --- a/application/admin/controller/ReceiptOrder.php +++ b/application/admin/controller/ReceiptOrder.php @@ -2,6 +2,7 @@ namespace app\admin\controller; +use app\admin\service\ReceiptOrderDao; use app\common\controller\Backend; use think\Db; use think\exception\PDOException; @@ -184,4 +185,15 @@ class ReceiptOrder extends Backend $this->view->assign("row", $row); return $this->view->fetch(); } + + /** + * 保存记录 + * @return \think\response\Json + */ + public function save(){ + $params=$this->request->post(); + $service = new ReceiptOrderDao(); + $result = $service->save($params); + return json($result); + } } diff --git a/application/admin/service/ReceiptOrderDao.php b/application/admin/service/ReceiptOrderDao.php new file mode 100644 index 0000000..c48ce46 --- /dev/null +++ b/application/admin/service/ReceiptOrderDao.php @@ -0,0 +1,91 @@ + $param['name'] + ]; + $receiptOrder = new ReceiptOrder(); + if (empty($param['id'])) { + $id = $receiptOrder->insertGetId($data); + return Util::returnArrSu("", $id); + } else { + $receiptOrder->save($data, ['id' => $param['id']]); + return Util::returnArrSu("", $param['id']); + } + } catch (Exception $e) { + return Util::returnArrEr("更新主订单失败:" . $e->getMessage()); + } + } + + /** + * 修改状态 + * @param $id + * @param $status + * @return array + */ + public function setStatus($id, $status) + { + try { + $receiptOrder = new ReceiptOrder(); + $receiptOrder->save(['status' => $status], ['id' => $id]); + return Util::returnArrSu(); + } catch (Exception $e) { + return Util::returnArrEr("修改状态失败" . $e->getMessage()); + } + } + + + /** + * 获取列表 + * @param $param + * @return array + */ + public function getList($param) + { + try { + $where = []; + if (!empty($param['name'])) { + $where['name'] = $param['name']; + } + if ($param['status'] != 'all') { + $where["status"] = $param['status']; + } + $offset = ($param['pageNum'] - 1) * $param['pageSize']; + $receiptOrder = new ReceiptOrder(); + $list = $receiptOrder + ->alias("a") + ->join('hbp_order_main b', 'a.id = b.receipt_order_id', 'left') + ->field("a.*,count(1),sum(b.total_amount)") + ->group("a.id") + ->where($where); + $total = $list->count(); + $list = $list->limit($offset, $param['pageSize'])->select(); + $data = ["total" => $total, "list" => $list]; + return Util::returnArrSu("", $data); + } catch (Exception $e) { + return Util::returnArrSu("", ["total" => 0, "list" => []]); + } + } +} \ No newline at end of file diff --git a/application/admin/service/ReceiptOrderService.php b/application/admin/service/ReceiptOrderService.php new file mode 100644 index 0000000..4e484e8 --- /dev/null +++ b/application/admin/service/ReceiptOrderService.php @@ -0,0 +1,34 @@ +save($param); + } + + /** + * 获取列表 + * @param $param + * @return array + */ + public function getList($param){ + $dao = new ReceiptOrderDao(); + return $dao->getList($param); + } +} \ No newline at end of file