123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- namespace app\admin\controller\qingdongams\customer;
- use addons\qingdongams\model\Staff;
- use app\common\controller\Backend;
- use think\Db;
- use think\exception\PDOException;
- use think\exception\ValidateException;
- /**
- * 设备管理
- *
- * @icon fa fa-circle-o
- */
- class Equipmentdevice extends Backend
- {
- /**
- * Equipmentdevice模型对象
- * @var \app\admin\model\qingdongams\customer\Equipmentdevice
- */
- protected $model = null;
- protected $Equipmentdevice = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\qingdongams\customer\Equipmentdevice;
- $this->Equipmentdevice = new \app\admin\model\qingdongams\customer\Equipmentdevice;
- $this->view->assign("statusList", $this->model->getStatusList());
- }
- public function index_no()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if (false === $this->request->isAjax()) {
- return $this->view->fetch();
- }
- //如果发送的来源是 Selectpage,则转发到 Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- [$where, $sort, $order, $offset, $limit] = $this->buildparams();
- $map=[];
- $idsArr = [];
-
- if($this->request->request('isselect')==1){
- $map['status']=0;
- }
- if ($this->request->request('ids')) {
- $ids = explode(',', $this->request->request('ids'));
- foreach ($ids as $value) {
- if ($value != "") {
- $idsArr[] = $value;
- }
- }
- }
- $list = $this->model
- ->where($where)
- ->where($map)
- ->whereNotIn('id', $idsArr)
- ->order($sort, $order)
- ->paginate($limit);
- $result = ['total' => $list->total(), 'rows' => $list->items()];
- return json($result);
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
- * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
- * 113.224.136.184
- * 112.38.101.236
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- public function indexs(){
- $info=$this->model->where(array('status'=>0))->select();
- $data['list']=$info;
- return $data;
- }
- public function select_add(){
- $info=Db::name('qingdongams_contract')->where(array('id'=>input('ids')))->find();
- if ($this->request->isAjax()) {
- $params = $this->request->post("row/a");
- $json_data=json_decode($params['device_ids'],true);
- $dev_ids= implode(',', array_column($json_data, 'customer_product_id'));
- $data['device_ids']=$dev_ids;
- $data['device_ids_json']=$params['device_ids'];
- $result = Db::name('qingdongams_contract')->where(array('id' => $info['id']))->update($data);
- foreach($json_data as $key=>$val){
- $res=$this->Equipmentdevice->where(array('id'=>$val['customer_product_id']))->update(array('status'=>1,'customer_id'=>$info['customer_id'],'contract_id'=>$info['id']));
- }
- if (!$result) {
- $this->error('绑定失败');
- }
- $this->success('绑定成功');
-
- }
- $this->assign('row', $info);
- return $this->view->fetch();
- }
- /**
- * 查看
- */
- public function index()
- {
- //当前是否为关联查询
- $this->relationSearch = true;
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
-
- // $info=$this->model->where(array('status'=>0))->select();
- return $this->selectpage();
- // $data['list']=$info;
- // return $data;
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
-
- $map=[];
- if($this->request->request('isselect')==1){
- $map['customer_id']=$this->request->request('customer_id');
- $ids = $this->request->request('ids');
- if($ids){
- $map['id'] = ['not in', $ids];
- }
- }
- $list = $this->model
- ->where($where)
- ->where($map)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $value) {
- $type_id_arr = explode(',', $value['type_id']);
- $type_name = \app\admin\model\qingdongams\customer\Equipmenttype::where(['id'=> ['in', $type_id_arr]])->column('name');
- $value['type_id'] = implode(',', $type_name);
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- $this->assignconfig('isselect', $this->request->request('isselect'));
- $this->assignconfig('customer_id', $this->request->request('customer_id'));
- return $this->view->fetch();
- }
- /**
- * 添加
- *
- * @return string
- * @throws \think\Exception
- */
- public function add()
- {
- if (false === $this->request->isPost()) {
- return $this->view->fetch();
- }
- $params = $this->request->post('row/a');
- if (empty($params)) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $params = $this->preExcludeFields($params);
- if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
- $params[$this->dataLimitField] = $this->auth->id;
- }
- $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 . '.add' : $name) : $this->modelValidate;
- $this->model->validateFailException()->validate($validate);
- }
- // 添加设备时判断是否需要增加客户id
- $customer_id = $this->request->request('customer_id') ?? '';
- if ($customer_id) {
- $params['customer_id'] = $customer_id;
- }
- $result = $this->model->allowField(true)->save($params);
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if ($result === false) {
- $this->error(__('No rows were inserted'));
- }
- $this->success();
- }
- /**
- * 搜索下拉列表
- */
- public function typeList()
- {
- $data = ['searchlist' => \app\admin\model\qingdongams\customer\Equipmenttype::getList()];
- $this->success('', null, $data);
- }
- }
|