model = new \addons\qingdong\model\Order(); } /** * 产品列表 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); //获取所有权限 if ($this->request->isAjax()) { list($where, $sort, $order, $offset, $limit) = $this->buildparams(null,null,0); $sort="id"; $order="desc"; //负责人为空 $list = $this->model->where($where)->where('pay_status','=',1)->order($sort, $order)->paginate($limit); $row=$list->items(); foreach ($row as $k => $v) { $staff = Db::name("qingdong_staff")->where('id','=',$v['user_id'])->find(); $v['user_name'] = $staff['name']; $v['user_mobile'] = $staff['mobile']; $company = Db::name("company")->where('id','=',$v['cid'])->find(); $v['company_name'] = $company['name']; $v['pay_time'] = $v['pay_time']?date('Y-m-d H:i:s',$v['pay_time']):'--'; $row[$k] = $v; } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } /** * 添加产品 */ public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { $params = $this->preExcludeFields($params); //查询权限等级是否已存在 $count = $this->model->where("name","=",$params['name'])->count(); if($count>0){ $this->error("企业名称已存在!!"); } $result = false; Db::startTrans(); try { $result = $this->model->allowField(true)->save($params); Db::commit(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success(); } else { $this->error(__('No rows were inserted')); } } $this->error(__('Parameter %s can not be empty', '')); } return $this->view->fetch(); } /** * 修改产品 */ public function edit($ids = null) { $map['id'] = $ids??CID; if ($this->request->isAjax()) { $params = $this->request->post('row/a'); $params = $this->preExcludeFields($params); //查询权限等级是否已存在 $count = $this->model->where("name","=",$params['name'])->where("id","neq",$ids)->count(); if($count>0){ $this->error("企业名称已存在!!"); } $result = false; Db::startTrans(); try { $result = $this->model->allowField(true)->update($params, $map); Db::commit(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success('修改成功'); } else { $this->error('修改失败'); } } $data = $this->model->where($map)->find(); //获取所有权限 $list2 = Db::name('auth_group')->where('status','=','normal')->select(); $roles = array_column($list2,'name','id'); $data['group_name'] = $roles[$data['group_id']]??''; $data['expire_time_str'] = isset($data['expire_time']) && $data['expire_time']>0 ? date('Y-m-d',$data['expire_time']):'-'; $this->view->assign("row", $data); return $this->view->fetch(); } /** * 产品详情 */ public function detail($ids = null) { $row = $this->model->get($ids); $this->assign('row', $row); $this->assign('ids', $ids); return $this->view->fetch(); } /** * 删除产品 */ public function del($ids = "") { if (!$this->request->isPost()) { $this->error(__("Invalid parameters")); } $ids = $ids ? $ids : $this->request->post("ids"); $row = $this->model->get($ids); $this->modelValidate = true; if (!$row) { $this->error(__('No Results were found')); } $row->delete(); $this->success(); } /** * 获取产品分类 */ public function get_group(){ $countrys = AuthGroup::where('status','=','normal')->field('id,name')->order('id desc')->select(); return json(['list' => $countrys, 'total' => count($countrys)]); } }