Orderuse.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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(['companyNo', 'companyName', '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. ], 'post', 'trim');
  82. // $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  83. // $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  84. $where = [['is_del', "=", 0]];
  85. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  86. if ($param['status'] !== "") $where [] = ['status', "=", $param['status']];
  87. // $order_use = isset($this->post['order_use']) && $this->post['order_use'] !== "" ? trim($this->post['order_use']) : "";
  88. if ($param['order_use'] !== "") $where [] = ['order_use', "like", '%' . $param['order_use'] . '%'];
  89. // $creater = isset($this->post['creater']) && $this->post['creater'] !== "" ? trim($this->post['creater']) : "";
  90. if ($param['creater'] !== "") $where [] = ['creater', "like", '%' . $param['creater'] . '%'];
  91. // $start = isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  92. if ($param['start'] !== "") $where[] = ['addtime', ">=", date('Y-m-d H:i:s', strtotime($param['start']))];
  93. // $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  94. if ($param['end'] !== "") $where[] = ['addtime', "<", date('Y-m-d H:i:s', strtotime($param['end']) + 24 * 3600)];
  95. // $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  96. if ($param['company_name'] !== "") $where[] = ["createrid", 'in', get_company_item_user_by_name($param['company_name'])];
  97. if ($param['companyNo'] !== "") $where[] = ["companyNo", '=', $param['companyNo']];
  98. $count = Db::name('order_use')
  99. ->where($where)
  100. ->count('id');
  101. $list = Db::name('order_use')
  102. ->where($where)
  103. ->page($param['page'], $param['size'])
  104. ->order(['addtime' => 'desc', 'id' => 'desc'])
  105. ->select()
  106. ->toArray();
  107. //补全部门信息
  108. $all_createrid = array_column($list, 'createrid');
  109. $item = get_company_name_by_uid($all_createrid);
  110. foreach ($list as &$value) {
  111. $val['company_name'] = $item[$value['createrid']] ?? '';
  112. }
  113. return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
  114. }
  115. public function edit()
  116. {
  117. $param = $this->request->only(['id', 'companyNo', 'companyName', 'order_use'], 'post', 'trim');
  118. $val = Validate::rule([
  119. 'id' => 'require|number|gt:0',
  120. 'companyNo|公司编码' => 'require|length:18',
  121. 'companyName|公司名称' => 'require|max:255',
  122. 'order_use|订单用途' => 'require|max:255',
  123. ]);
  124. if ($val->check($param) == false) return json_show(1004, $val->getError());
  125. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  126. // if ($id == "") {
  127. // return error_show(1002, "参数id不能为空");
  128. // }
  129. // $info = Db::name('order_use')->where(['id' => $id, 'is_del' => 0])->find();
  130. // if ($info == "") {
  131. // return error_show(1004, "未找到数据");
  132. // }
  133. // $order_use = isset($this->post['order_use']) && $this->post['order_use'] !== "" ? trim($this->post['order_use']) : "";
  134. // if ($order_use == "") {
  135. // return error_show(1002, "参数order_use不能为空");
  136. // }
  137. // $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "0";
  138. // $data = [
  139. // "id" => $id,
  140. // "order_use" => $order_use,
  141. // "is_del" => 0,
  142. // "updatetime" => date("Y-m-d H:i:s")
  143. // ];
  144. $tmp = Db::name('order_use')
  145. ->field('id')
  146. ->where([
  147. 'is_del' => 0,
  148. 'companyNo' => $param['companyNo'],
  149. 'order_use' => $param['order_use'],
  150. ])
  151. ->where('id', '<>', $param['id'])
  152. ->findOrEmpty();
  153. if (!empty($tmp)) return json_show(1004, '同一公司下该订单用途已存在');
  154. $datainfo = Db::name("order_use")
  155. ->where(['is_del' => 0, 'id' => $param['id']])
  156. ->update([
  157. "companyNo" => $param['companyNo'],
  158. "companyName" => $param['companyName'],
  159. "order_use" => $param['order_use'],
  160. "updatetime" => date("Y-m-d H:i:s")
  161. ]);
  162. return $datainfo ? app_show(0, "编辑成功") : error_show(1002, "编辑失败");
  163. // if ($datainfo) {
  164. // return error_show(0, "编辑成功");
  165. // } else {
  166. // return error_show(1002, "编辑失败");
  167. // }
  168. }
  169. public function dele()
  170. {
  171. $id = $this->request->filter('trim')->post('id/d', 0);
  172. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  173. // if ($id == "") {
  174. // return error_show(1002, "参数id不能为空");
  175. // }
  176. // $info = Db::name('order_use')->where(['id' => $id, 'is_del' => 0])->find();
  177. // if (empty($info)) {
  178. // return error_show(1004, "未找到数据");
  179. // }
  180. $item = Db::name('order_use')
  181. ->where(['is_del' => 0, 'id' => $id])
  182. ->update(['is_del' => 1, 'updatetime' => date("Y-m-d H:i:s")]);
  183. return $item ? app_show(0, "删除成功") : error_show(1002, "删除失败");
  184. // if ($item) {
  185. // return error_show(0, "删除成功");
  186. // } else {
  187. // return error_show(1002, "删除失败");
  188. // }
  189. }
  190. public function status()
  191. {
  192. $param = $this->request->only(['id', 'status'], 'post', 'trim');
  193. $val = Validate::rule([
  194. 'id' => 'require|number|gt:0',
  195. 'status|状态' => 'require|number|in:0,1',
  196. ]);
  197. if ($val->check($param) == false) return json_show(1004, $val->getError());
  198. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  199. // if ($id == "") {
  200. // return error_show(1002, "参数id不能为空");
  201. // }
  202. // $info = Db::name("order_use")->where([["id", "=", $id], ["is_del", "=", 0]])->find();
  203. // if (!$info) {
  204. // return error_show(1002, "未找到对应数据");
  205. // }
  206. // $msg = $info['status'] == 0 ? "启用" : "禁用";
  207. // $info['status'] = $info['status'] == 0 ? 1 : 0;
  208. // $info['updatetime'] = date("Y-m-d H:i:s");
  209. $in = Db::name("order_use")
  210. ->where(['is_del' => 0, 'id' => $param['id']])
  211. ->where('status', '<>', $param['status'])
  212. ->update(['status' => $param['status'], 'updatetime' => date("Y-m-d H:i:s")]);
  213. return $in ? app_show(0, "操作成功") : error_show(1004, "操作失败");
  214. // if ($in) {
  215. // return app_show(0, "{$msg}成功");
  216. // } else {
  217. // return error_show(1004, "{$msg}失败");
  218. // }
  219. }
  220. public function info()
  221. {
  222. $id = $this->request->filter('trim')->post('id/d', 0);
  223. // $id = isset($this->post['id']) && $this->post['id'] !== "" ? trim($this->post['id']) : "";
  224. // if ($id == "") {
  225. // return error_show(1002, "参数id不能为空");
  226. // }
  227. $info = Db::name('order_use')
  228. ->where(['id' => $id, 'is_del' => 0])
  229. ->findOrEmpty();
  230. // if (empty($info)) {
  231. // return error_show(1004, '未找到数据');
  232. // }
  233. // return app_show(0, "获取成功", $info);
  234. return empty($info) ? error_show(1004, '未找到数据') : app_show(0, "获取成功", $info);
  235. }
  236. }