Orderuse.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. use think\facade\Validate;
  6. //订单用途
  7. class Orderuse extends Base
  8. {
  9. public function create()
  10. {
  11. $param = $this->request->only(['order_use'], 'post', 'trim');
  12. $val = Validate::rule([
  13. 'order_use|订单用途' => 'require|max:255',
  14. ]);
  15. if ($val->check($param) == false) return json_show(1004, $val->getError());
  16. $tmp = Db::name('order_use')
  17. ->field('id')
  18. ->where([
  19. 'is_del' => 0,
  20. 'order_use' => $param['order_use'],
  21. ])
  22. ->findOrEmpty();
  23. if (!empty($tmp)) return json_show(1004, '同一公司下该订单用途已存在');
  24. $datainfo = Db::name('order_use')->insert([
  25. "order_use" => $param['order_use'],
  26. "creater" => $this->uname,
  27. "createrid" => $this->uid,
  28. "status" => 0,
  29. "is_del" => 0,
  30. "addtime" => date("Y-m-d H:i:s"),
  31. "updatetime" => date("Y-m-d H:i:s")
  32. ]);
  33. return $datainfo ? app_show(0, "新建成功") : error_show(1002, "新建失败");
  34. }
  35. public function list()
  36. {
  37. $param = $this->request->only([
  38. 'page' => 1,
  39. 'size' => 10,
  40. 'status' => '',
  41. 'order_use' => '',
  42. 'creater' => '',
  43. 'start' => '',
  44. 'end' => '',
  45. 'company_name' => '',
  46. // 'companyNo' => '',
  47. 'relaComNo' => '',
  48. ], 'post', 'trim');
  49. // $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  50. // $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  51. $where = [['is_del', "=", 0]];
  52. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  53. if ($param['status'] !== "") $where [] = ['status', "=", $param['status']];
  54. // $order_use = isset($this->post['order_use']) && $this->post['order_use'] !== "" ? trim($this->post['order_use']) : "";
  55. if ($param['order_use'] !== "") $where [] = ['order_use', "like", '%' . $param['order_use'] . '%'];
  56. // $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? trim($this->post['creater']) : "";
  57. if ($param['creater'] !== "") $where [] = ['creater', "like", '%' . $param['creater'] . '%'];
  58. // $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  59. if ($param['start'] !== "") $where[] = ['addtime', ">=", date('Y-m-d H:i:s', strtotime($param['start']))];
  60. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  61. if ($param['end'] !== "") $where[] = ['addtime', "<", date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)];
  62. // $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  63. if ($param['company_name'] !== "") $where[] = ["createrid", 'in', get_company_item_user_by_name($param['company_name'])];
  64. // if ($param['companyNo'] !== "") $where[] = ["companyNo", '=', $param['companyNo']];
  65. if ($param['relaComNo'] !== "") $where[] = ["companyNo", '=', $param['relaComNo']];
  66. $count = Db::name('order_use')
  67. ->where($where)
  68. ->count('id');
  69. $list = Db::name('order_use')
  70. ->where($where)
  71. ->page($param['page'], $param['size'])
  72. ->order(['addtime' => 'desc', 'id' => 'desc'])
  73. ->select()
  74. ->toArray();
  75. //补全部门信息
  76. $all_createrid = array_column($list, 'createrid');
  77. $item = get_company_name_by_uid($all_createrid);
  78. foreach ($list as &$value) {
  79. $val['company_name'] = $item[$value['createrid']] ?? '';
  80. }
  81. return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
  82. }
  83. public function edit()
  84. {
  85. $param = $this->request->only(['id', 'order_use'], 'post', 'trim');
  86. $val = Validate::rule([
  87. 'id' => 'require|number|gt:0',
  88. 'order_use|订单用途' => 'require|max:255',
  89. ]);
  90. if ($val->check($param) == false) return json_show(1004, $val->getError());
  91. $tmp = Db::name('order_use')
  92. ->field('id')
  93. ->where([
  94. 'is_del' => 0,
  95. 'order_use' => $param['order_use'],
  96. ])
  97. ->where('id', '<>', $param['id'])
  98. ->findOrEmpty();
  99. if (!empty($tmp)) return json_show(1004, '同一公司下该订单用途已存在');
  100. $datainfo = Db::name("order_use")
  101. ->where(['is_del' => 0, 'id' => $param['id']])
  102. ->update([
  103. "order_use" => $param['order_use'],
  104. "updatetime" => date("Y-m-d H:i:s")
  105. ]);
  106. return $datainfo ? app_show(0, "编辑成功") : error_show(1002, "编辑失败");
  107. }
  108. public function dele()
  109. {
  110. $id = $this->request->filter('trim')->post('id/d', 0);
  111. $item = Db::name('order_use')
  112. ->where(['is_del' => 0, 'id' => $id])
  113. ->update(['is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  114. return $item ? app_show(0, "删除成功") : error_show(1002, "删除失败");
  115. }
  116. public function status()
  117. {
  118. $param = $this->request->only(['id', 'status'], 'post', 'trim');
  119. $val = Validate::rule([
  120. 'id' => 'require|number|gt:0',
  121. 'status|状态' => 'require|number|in:0,1',
  122. ]);
  123. if ($val->check($param) == false) return json_show(1004, $val->getError());
  124. $in = Db::name("order_use")
  125. ->where(['is_del' => 0, 'id' => $param['id']])
  126. ->where('status', '<>', $param['status'])
  127. ->update(['status' => $param['status'], 'updatetime' => date("Y-m-d H:i:s")]);
  128. return $in ? app_show(0, "操作成功") : error_show(1004, "操作失败");
  129. }
  130. public function info()
  131. {
  132. $id = $this->request->filter('trim')->post('id/d', 0);
  133. $info = Db::name('order_use')
  134. ->where(['id' => $id, 'is_del' => 0])
  135. ->findOrEmpty();
  136. return empty($info) ? error_show(1004, '未找到数据') : app_show(0, "获取成功", $info);
  137. }
  138. }