FCleanTask.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class FCleanTask extends Auth {
  6. public function __construct(App $app = null) {
  7. parent::__construct($app);
  8. $this->model = new \app\common\model\FCleanTask();
  9. $this->table = $this->model->table;
  10. }
  11. public function index() {
  12. if (request()->isAjax()) {
  13. //分页参数
  14. $length = input('rows', 10, 'intval'); //每页条数
  15. $page = input('page', 1, 'intval'); //第几页
  16. $start = ($page - 1) * $length; //分页开始位置
  17. //排序
  18. $sortRow = input('sidx', 'id', 'trim'); //排序列
  19. $sort = input('sord', 'desc', 'trim'); //排序方式
  20. $order = $sortRow . ' ' . $sort;
  21. $title = input('title', '', 'trim');
  22. if ($title) {
  23. $map[] = ['title', 'like', '%' . $title . '%'];
  24. }
  25. $enable = input('enable', '', 'trim');
  26. if ($enable != '') {
  27. $map[] = ['enable', '=', $enable];
  28. }
  29. $status = input('status', '', 'trim');
  30. if ($status != '') {
  31. $map[] = ['status', '=', $status];
  32. }
  33. $map[] = ['del', '=', 0];
  34. $map[] = ['org_id', '=', $this->orgId];
  35. $map = empty($map) ? true : $map;
  36. //数据查询
  37. $lists = db($this->table)->where($map)->limit($start, $length)->order($order)->select();
  38. foreach ($lists as $k => $v) {
  39. $userlist = Db::name('f_clean_task_user')
  40. ->alias('f_clean_task_user')
  41. ->join('user user', 'user.id = clean_task_user.user_id')
  42. ->field('user.id,user.real_name')
  43. ->where('clean_task_user.task_id', $v['id'])
  44. ->select();
  45. $users = array();
  46. foreach ($userlist as $kk => $vv) {
  47. $users[] = $vv['real_name'];
  48. }
  49. $lists[$k]['user'] = implode(',', $users);
  50. }
  51. //数据返回
  52. $totalCount = db($this->table)->where($map)->count();
  53. $totalPage = ceil($totalCount / $length);
  54. $result['page'] = $page;
  55. $result['total'] = $totalPage;
  56. $result['records'] = $totalCount;
  57. $result['rows'] = $lists;
  58. return json($result);
  59. }
  60. else {
  61. $this->assign('m_name', '计划管理');
  62. return $this->fetch();
  63. }
  64. }
  65. /**
  66. * 新增/编辑
  67. */
  68. public function add($id = 0) {
  69. if (request()->isPost()) {
  70. $res = $this->model->updates();
  71. if ($res) {
  72. $this->success('操作成功', url('index'));
  73. }
  74. else {
  75. $this->error($this->model->getError());
  76. }
  77. }
  78. else {
  79. if ($id) {
  80. $info = db($this->table)->where('id', $id)->find();
  81. $info['type'] = db('f_clean_task_form')
  82. ->where('task_id', $id)
  83. ->column('form_id');
  84. $info['user'] = db('f_clean_task_user')
  85. ->where('task_id', $id)
  86. ->column('user_id');
  87. $this->assign('info', $info);
  88. }
  89. $this->assign('user', (new \app\common\model\User())->getCleanWorker());
  90. $this->assign('type', (new \app\common\model\FCleanType())->getGroupList());
  91. return $this->fetch();
  92. }
  93. }
  94. /**
  95. * 删除记录
  96. * @param int $id
  97. */
  98. public function del($id = 0) {
  99. if (!$id) {
  100. $this->error('参数错误');
  101. }
  102. $res = db($this->table)->where('id', $id)->update([
  103. 'del'=>1,
  104. 'del_user_id'=>is_login(),
  105. 'del_datetime'=>getTime(),
  106. ]);
  107. if ($res) {
  108. $this->success('删除成功');
  109. }
  110. else {
  111. $this->error('删除失败');
  112. }
  113. }
  114. /**
  115. * 改变字段值
  116. * @param int $fv
  117. * @param string $fn
  118. * @param int $fv
  119. */
  120. public function changeField($id = 0, $fn = '', $fv = 0) {
  121. if (!$fn || !$id) {
  122. $this->error('参数错误');
  123. }
  124. $res = db($this->table)->where('id', $id)->setField($fn, $fv);
  125. if ($res) {
  126. $this->success('操作成功');
  127. }
  128. else {
  129. $this->error('操作失败');
  130. }
  131. }
  132. public function details($id = 0){
  133. $info = Db::name('f_clean_task')->where('id',$id)->find();
  134. if(!$info){
  135. $this->error('参数错误');
  136. }
  137. $info['check_user_name'] = Db::name('user')->where('id',$info['check_user'])->value('real_name');
  138. $taskUser = Db::name('f_clean_task_user')
  139. ->alias('ctu')
  140. ->join('user u','u.id=ctu.user_id')
  141. ->where('ctu.task_id',$info['id'])
  142. ->column('u.real_name');
  143. $info['task_user'] = $taskUser?implode(',',$taskUser):'';
  144. $taskFormId = Db::name('f_clean_task_form')->where('task_id',$id)->column('form_id');
  145. $addr = Db::name('f_clean_type')
  146. ->alias('ct')
  147. ->field('cf.id,ct.title')
  148. ->join('f_clean_form cf','cf.type_id=ct.id')
  149. ->whereIn('cf.id',$taskFormId)
  150. ->select();
  151. foreach ($addr as $k=>$v){
  152. $record = Db::name('f_clean_record')
  153. ->alias('cr')
  154. ->field('cr.*,u.real_name')
  155. ->join('user u','u.id=cr.user_id')
  156. ->where('cr.task_id',$id)
  157. ->where('cr.form_id',$v['id'])
  158. ->find();
  159. if($record){
  160. $record['check_json'] = [];
  161. if($record['check_json']){
  162. $cjson = json_decode($record['check_json'],true);
  163. foreach ($cjson as $kk=>$vv){
  164. $address = Db::name('address')->where('id',$vv)->value('title');
  165. $cjson = [
  166. 'addr'=>$address,
  167. 'status'=>$vv['status']
  168. ];
  169. }
  170. $record['check_json'] = $cjson;
  171. }
  172. }
  173. $addr[$k]['record'] = $record;
  174. }
  175. $info['formList'] = $addr;
  176. $this->assign('info',$info);
  177. return $this->fetch();
  178. }
  179. public function subDetail(){
  180. $id = input('id');
  181. $info = Db::name('f_clean_record')->where('id',$id)->find();
  182. $info['user_name'] = Db::name('user')->where('id',$info['user_id'])->value('real_name');
  183. $info['task_title'] = Db::name('f_clean_task')->where('id',$info['task_id'])->value('title');
  184. if($info['check_json']){
  185. $cjson = json_decode($info['check_json'],true);
  186. $tarr = [];
  187. foreach ($cjson as $kk=>$vv){
  188. $address = Db::name('address')->where('id',$vv['id'])->value('title');
  189. $tarr[] = [
  190. 'addr'=>$address,
  191. 'status'=>$vv['status']
  192. ];
  193. }
  194. $info['check_json'] = $tarr;
  195. }
  196. $info['items'] = Db::name('f_clean_record_items')
  197. ->alias('cri')
  198. ->field('mg.title,cri.*')
  199. ->join('mate_goods mg','mg.id=cri.items_id')
  200. ->where('cri.record_id',$info['id'])
  201. ->select();
  202. $this->assign('info',$info);
  203. return $this->fetch();
  204. }
  205. }