123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- namespace app\admin\controller;
- use think\App;
- use think\facade\Db;
- use think\facade\Validate;
- //订单用途
- class Orderuse extends Base
- {
- public function create()
- {
- $param = $this->request->only(['order_use'], 'post', 'trim');
- $val = Validate::rule([
- // 'companyNo|公司编码' => 'require|length:18',
- // 'companyName|公司名称' => 'require|max:255',
- 'order_use|订单用途' => 'require|max:255',
- ]);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- // $order_use = isset($this->post['order_use']) && $this->post['order_use']!=="" ? trim($this->post['order_use']):"";
- // if($order_use==""){
- // return error_show(1002,"参数order_use不能为空");
- // }
- // $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
- // if($token==''){
- // return error_show(1005,"参数token不能为空");
- // }
- // $user =GetUserInfo($token);
- // if(empty($user)||$user['code']!=0){
- // return error_show(1002,"创建人数据不存在");
- // }
- // $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
- // $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
- // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"0";
- // $data =[
- // "order_use"=>$order_use,
- // "creater"=>$creater,
- // "createrid"=>$createrid,
- // "status"=>0,
- // "is_del"=>0,
- // "addtime"=>date("Y-m-d H:i:s"),
- // "updatetime"=>date("Y-m-d H:i:s")
- // ];
- $tmp = Db::name('order_use')
- ->field('id')
- ->where([
- 'is_del' => 0,
- // 'companyNo' => $param['companyNo'],
- 'order_use' => $param['order_use'],
- ])
- ->findOrEmpty();
- if (!empty($tmp)) return json_show(1004, '同一公司下该订单用途已存在');
- $datainfo = Db::name('order_use')->insert([
- // "companyNo" => $param['companyNo'],
- // "companyName" => $param['companyName'],
- "order_use" => $param['order_use'],
- "creater" => $this->uname,
- "createrid" => $this->uid,
- "status" => 0,
- "is_del" => 0,
- "addtime" => date("Y-m-d H:i:s"),
- "updatetime" => date("Y-m-d H:i:s")
- ]);
- return $datainfo ? app_show(0, "新建成功") : error_show(1002, "新建失败");
- // if($datainfo){
- // return error_show(0,"新建成功");
- // }else{
- // return error_show(1002,"新建失败");
- // }
- }
- public function list()
- {
- $param = $this->request->only([
- 'page' => 1,
- 'size' => 10,
- 'status' => '',
- 'order_use' => '',
- 'creater' => '',
- 'start' => '',
- 'end' => '',
- 'company_name' => '',
- // 'companyNo' => '',
- 'relaComNo' => '',
- ], 'post', 'trim');
- // $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- // $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $where = [['is_del', "=", 0]];
- // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
- if ($param['status'] !== "") $where [] = ['status', "=", $param['status']];
- // $order_use = isset($this->post['order_use']) && $this->post['order_use'] !== "" ? trim($this->post['order_use']) : "";
- if ($param['order_use'] !== "") $where [] = ['order_use', "like", '%' . $param['order_use'] . '%'];
- // $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? trim($this->post['creater']) : "";
- if ($param['creater'] !== "") $where [] = ['creater', "like", '%' . $param['creater'] . '%'];
- // $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
- if ($param['start'] !== "") $where[] = ['addtime', ">=", date('Y-m-d H:i:s', strtotime($param['start']))];
- // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
- if ($param['end'] !== "") $where[] = ['addtime', "<", date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)];
- // $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
- if ($param['company_name'] !== "") $where[] = ["createrid", 'in', get_company_item_user_by_name($param['company_name'])];
- // if ($param['companyNo'] !== "") $where[] = ["companyNo", '=', $param['companyNo']];
- if ($param['relaComNo'] !== "") $where[] = ["companyNo", '=', $param['relaComNo']];
- $count = Db::name('order_use')
- ->where($where)
- ->count('id');
- $list = Db::name('order_use')
- ->where($where)
- ->page($param['page'], $param['size'])
- ->order(['addtime' => 'desc', 'id' => 'desc'])
- ->select()
- ->toArray();
- //补全部门信息
- $all_createrid = array_column($list, 'createrid');
- $item = get_company_name_by_uid($all_createrid);
- foreach ($list as &$value) {
- $val['company_name'] = $item[$value['createrid']] ?? '';
- }
- return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
- }
- public function edit()
- {
- $param = $this->request->only(['id', 'order_use'], 'post', 'trim');
- $val = Validate::rule([
- 'id' => 'require|number|gt:0',
- // 'companyNo|公司编码' => 'require|length:18',
- // 'companyName|公司名称' => 'require|max:255',
- 'order_use|订单用途' => 'require|max:255',
- ]);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- // if ($id == "") {
- // return error_show(1002, "参数id不能为空");
- // }
- // $info = Db::name('order_use')->where(['id' => $id, 'is_del' => 0])->find();
- // if ($info == "") {
- // return error_show(1004, "未找到数据");
- // }
- // $order_use = isset($this->post['order_use']) && $this->post['order_use'] !== "" ? trim($this->post['order_use']) : "";
- // if ($order_use == "") {
- // return error_show(1002, "参数order_use不能为空");
- // }
- // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
- // $data = [
- // "id" => $id,
- // "order_use" => $order_use,
- // "is_del" => 0,
- // "updatetime" => date("Y-m-d H:i:s")
- // ];
- $tmp = Db::name('order_use')
- ->field('id')
- ->where([
- 'is_del' => 0,
- // 'companyNo' => $param['companyNo'],
- 'order_use' => $param['order_use'],
- ])
- ->where('id', '<>', $param['id'])
- ->findOrEmpty();
- if (!empty($tmp)) return json_show(1004, '同一公司下该订单用途已存在');
- $datainfo = Db::name("order_use")
- ->where(['is_del' => 0, 'id' => $param['id']])
- ->update([
- // "companyNo" => $param['companyNo'],
- // "companyName" => $param['companyName'],
- "order_use" => $param['order_use'],
- "updatetime" => date("Y-m-d H:i:s")
- ]);
- return $datainfo ? app_show(0, "编辑成功") : error_show(1002, "编辑失败");
- // if ($datainfo) {
- // return error_show(0, "编辑成功");
- // } else {
- // return error_show(1002, "编辑失败");
- // }
- }
- public function dele()
- {
- $id = $this->request->filter('trim')->post('id/d', 0);
- // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- // if ($id == "") {
- // return error_show(1002, "参数id不能为空");
- // }
- // $info = Db::name('order_use')->where(['id' => $id, 'is_del' => 0])->find();
- // if (empty($info)) {
- // return error_show(1004, "未找到数据");
- // }
- $item = Db::name('order_use')
- ->where(['is_del' => 0, 'id' => $id])
- ->update(['is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
- return $item ? app_show(0, "删除成功") : error_show(1002, "删除失败");
- // if ($item) {
- // return error_show(0, "删除成功");
- // } else {
- // return error_show(1002, "删除失败");
- // }
- }
- public function status()
- {
- $param = $this->request->only(['id', 'status'], 'post', 'trim');
- $val = Validate::rule([
- 'id' => 'require|number|gt:0',
- 'status|状态' => 'require|number|in:0,1',
- ]);
- if ($val->check($param) == false) return json_show(1004, $val->getError());
- // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
- // if ($id == "") {
- // return error_show(1002, "参数id不能为空");
- // }
- // $info = Db::name("order_use")->where([["id", "=", $id], ["is_del", "=", 0]])->find();
- // if (!$info) {
- // return error_show(1002, "未找到对应数据");
- // }
- // $msg = $info['status'] == 0 ? "启用" : "禁用";
- // $info['status'] = $info['status'] == 0 ? 1 : 0;
- // $info['updatetime'] = date("Y-m-d H:i:s");
- $in = Db::name("order_use")
- ->where(['is_del' => 0, 'id' => $param['id']])
- ->where('status', '<>', $param['status'])
- ->update(['status' => $param['status'], 'updatetime' => date("Y-m-d H:i:s")]);
- return $in ? app_show(0, "操作成功") : error_show(1004, "操作失败");
- // if ($in) {
- // return app_show(0, "{$msg}成功");
- // } else {
- // return error_show(1004, "{$msg}失败");
- // }
- }
- public function info()
- {
- $id = $this->request->filter('trim')->post('id/d', 0);
- // $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
- // if ($id == "") {
- // return error_show(1002, "参数id不能为空");
- // }
- $info = Db::name('order_use')
- ->where(['id' => $id, 'is_del' => 0])
- ->findOrEmpty();
- // if (empty($info)) {
- // return error_show(1004, '未找到数据');
- // }
- // return app_show(0, "获取成功", $info);
- return empty($info) ? error_show(1004, '未找到数据') : app_show(0, "获取成功", $info);
- }
- }
|