Orderuse.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. // 'companyNo|公司编码' => 'require|length:18',
  14. // 'companyName|公司名称' => 'require|max:255',
  15. 'order_use|订单用途' => 'require|max:255',
  16. ]);
  17. if ($val->check($param) == false) return json_show(1004, $val->getError());
  18. // $order_use = isset($this->post['order_use']) && $this->post['order_use']!=="" ? trim($this->post['order_use']):"";
  19. // if($order_use==""){
  20. // return error_show(1002,"参数order_use不能为空");
  21. // }
  22. // $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  23. // if($token==''){
  24. // return error_show(1005,"参数token不能为空");
  25. // }
  26. // $user =GetUserInfo($token);
  27. // if(empty($user)||$user['code']!=0){
  28. // return error_show(1002,"创建人数据不存在");
  29. // }
  30. // $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  31. // $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  32. // $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"0";
  33. // $data =[
  34. // "order_use"=>$order_use,
  35. // "creater"=>$creater,
  36. // "createrid"=>$createrid,
  37. // "status"=>0,
  38. // "is_del"=>0,
  39. // "addtime"=>date("Y-m-d H:i:s"),
  40. // "updatetime"=>date("Y-m-d H:i:s")
  41. // ];
  42. $tmp = Db::name('order_use')
  43. ->field('id')
  44. ->where([
  45. 'is_del' => 0,
  46. // 'companyNo' => $param['companyNo'],
  47. 'order_use' => $param['order_use'],
  48. ])
  49. ->findOrEmpty();
  50. if (!empty($tmp)) return json_show(1004, '同一公司下该订单用途已存在');
  51. $datainfo = Db::name('order_use')->insert([
  52. // "companyNo" => $param['companyNo'],
  53. // "companyName" => $param['companyName'],
  54. "order_use" => $param['order_use'],
  55. "creater" => $this->uname,
  56. "createrid" => $this->uid,
  57. "status" => 0,
  58. "is_del" => 0,
  59. "addtime" => date("Y-m-d H:i:s"),
  60. "updatetime" => date("Y-m-d H:i:s")
  61. ]);
  62. return $datainfo ? app_show(0, "新建成功") : error_show(1002, "新建失败");
  63. // if($datainfo){
  64. // return error_show(0,"新建成功");
  65. // }else{
  66. // return error_show(1002,"新建失败");
  67. // }
  68. }
  69. public function list()
  70. {
  71. $param = $this->request->only([
  72. 'page' => 1,
  73. 'size' => 10,
  74. 'status' => '',
  75. 'order_use' => '',
  76. 'creater' => '',
  77. 'start' => '',
  78. 'end' => '',
  79. 'company_name' => '',
  80. // 'companyNo' => '',
  81. 'relaComNo' => '',
  82. ], 'post', 'trim');
  83. // $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  84. // $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  85. $where = [['is_del', "=", 0]];
  86. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  87. if ($param['status'] !== "") $where [] = ['status', "=", $param['status']];
  88. // $order_use = isset($this->post['order_use']) && $this->post['order_use'] !== "" ? trim($this->post['order_use']) : "";
  89. if ($param['order_use'] !== "") $where [] = ['order_use', "like", '%' . $param['order_use'] . '%'];
  90. // $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? trim($this->post['creater']) : "";
  91. if ($param['creater'] !== "") $where [] = ['creater', "like", '%' . $param['creater'] . '%'];
  92. // $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  93. if ($param['start'] !== "") $where[] = ['addtime', ">=", date('Y-m-d H:i:s', strtotime($param['start']))];
  94. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  95. if ($param['end'] !== "") $where[] = ['addtime', "<", date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)];
  96. // $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  97. if ($param['company_name'] !== "") $where[] = ["createrid", 'in', get_company_item_user_by_name($param['company_name'])];
  98. // if ($param['companyNo'] !== "") $where[] = ["companyNo", '=', $param['companyNo']];
  99. if ($param['relaComNo'] !== "") $where[] = ["companyNo", '=', $param['relaComNo']];
  100. $count = Db::name('order_use')
  101. ->where($where)
  102. ->count('id');
  103. $list = Db::name('order_use')
  104. ->where($where)
  105. ->page($param['page'], $param['size'])
  106. ->order(['addtime' => 'desc', 'id' => 'desc'])
  107. ->select()
  108. ->toArray();
  109. //补全部门信息
  110. $all_createrid = array_column($list, 'createrid');
  111. $item = get_company_name_by_uid($all_createrid);
  112. foreach ($list as &$value) {
  113. $val['company_name'] = $item[$value['createrid']] ?? '';
  114. }
  115. return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
  116. }
  117. public function edit()
  118. {
  119. $param = $this->request->only(['id', 'order_use'], 'post', 'trim');
  120. $val = Validate::rule([
  121. 'id' => 'require|number|gt:0',
  122. // 'companyNo|公司编码' => 'require|length:18',
  123. // 'companyName|公司名称' => 'require|max:255',
  124. 'order_use|订单用途' => 'require|max:255',
  125. ]);
  126. if ($val->check($param) == false) return json_show(1004, $val->getError());
  127. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  128. // if ($id == "") {
  129. // return error_show(1002, "参数id不能为空");
  130. // }
  131. // $info = Db::name('order_use')->where(['id' => $id, 'is_del' => 0])->find();
  132. // if ($info == "") {
  133. // return error_show(1004, "未找到数据");
  134. // }
  135. // $order_use = isset($this->post['order_use']) && $this->post['order_use'] !== "" ? trim($this->post['order_use']) : "";
  136. // if ($order_use == "") {
  137. // return error_show(1002, "参数order_use不能为空");
  138. // }
  139. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
  140. // $data = [
  141. // "id" => $id,
  142. // "order_use" => $order_use,
  143. // "is_del" => 0,
  144. // "updatetime" => date("Y-m-d H:i:s")
  145. // ];
  146. $tmp = Db::name('order_use')
  147. ->field('id')
  148. ->where([
  149. 'is_del' => 0,
  150. // 'companyNo' => $param['companyNo'],
  151. 'order_use' => $param['order_use'],
  152. ])
  153. ->where('id', '<>', $param['id'])
  154. ->findOrEmpty();
  155. if (!empty($tmp)) return json_show(1004, '同一公司下该订单用途已存在');
  156. $datainfo = Db::name("order_use")
  157. ->where(['is_del' => 0, 'id' => $param['id']])
  158. ->update([
  159. // "companyNo" => $param['companyNo'],
  160. // "companyName" => $param['companyName'],
  161. "order_use" => $param['order_use'],
  162. "updatetime" => date("Y-m-d H:i:s")
  163. ]);
  164. return $datainfo ? app_show(0, "编辑成功") : error_show(1002, "编辑失败");
  165. // if ($datainfo) {
  166. // return error_show(0, "编辑成功");
  167. // } else {
  168. // return error_show(1002, "编辑失败");
  169. // }
  170. }
  171. public function dele()
  172. {
  173. $id = $this->request->filter('trim')->post('id/d', 0);
  174. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  175. // if ($id == "") {
  176. // return error_show(1002, "参数id不能为空");
  177. // }
  178. // $info = Db::name('order_use')->where(['id' => $id, 'is_del' => 0])->find();
  179. // if (empty($info)) {
  180. // return error_show(1004, "未找到数据");
  181. // }
  182. $item = Db::name('order_use')
  183. ->where(['is_del' => 0, 'id' => $id])
  184. ->update(['is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  185. return $item ? app_show(0, "删除成功") : error_show(1002, "删除失败");
  186. // if ($item) {
  187. // return error_show(0, "删除成功");
  188. // } else {
  189. // return error_show(1002, "删除失败");
  190. // }
  191. }
  192. public function status()
  193. {
  194. $param = $this->request->only(['id', 'status'], 'post', 'trim');
  195. $val = Validate::rule([
  196. 'id' => 'require|number|gt:0',
  197. 'status|状态' => 'require|number|in:0,1',
  198. ]);
  199. if ($val->check($param) == false) return json_show(1004, $val->getError());
  200. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  201. // if ($id == "") {
  202. // return error_show(1002, "参数id不能为空");
  203. // }
  204. // $info = Db::name("order_use")->where([["id", "=", $id], ["is_del", "=", 0]])->find();
  205. // if (!$info) {
  206. // return error_show(1002, "未找到对应数据");
  207. // }
  208. // $msg = $info['status'] == 0 ? "启用" : "禁用";
  209. // $info['status'] = $info['status'] == 0 ? 1 : 0;
  210. // $info['updatetime'] = date("Y-m-d H:i:s");
  211. $in = Db::name("order_use")
  212. ->where(['is_del' => 0, 'id' => $param['id']])
  213. ->where('status', '<>', $param['status'])
  214. ->update(['status' => $param['status'], 'updatetime' => date("Y-m-d H:i:s")]);
  215. return $in ? app_show(0, "操作成功") : error_show(1004, "操作失败");
  216. // if ($in) {
  217. // return app_show(0, "{$msg}成功");
  218. // } else {
  219. // return error_show(1004, "{$msg}失败");
  220. // }
  221. }
  222. public function info()
  223. {
  224. $id = $this->request->filter('trim')->post('id/d', 0);
  225. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  226. // if ($id == "") {
  227. // return error_show(1002, "参数id不能为空");
  228. // }
  229. $info = Db::name('order_use')
  230. ->where(['id' => $id, 'is_del' => 0])
  231. ->findOrEmpty();
  232. // if (empty($info)) {
  233. // return error_show(1004, '未找到数据');
  234. // }
  235. // return app_show(0, "获取成功", $info);
  236. return empty($info) ? error_show(1004, '未找到数据') : app_show(0, "获取成功", $info);
  237. }
  238. }