Daily.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. namespace app\admin\controller\qingdong\report;
  3. use addons\qingdong\model\File;
  4. use addons\qingdong\model\Remind;
  5. use addons\qingdong\model\Staff;
  6. use app\admin\controller\qingdong\Base;
  7. use app\common\controller\Backend;
  8. use addons\qingdong\model\Form;
  9. use addons\qingdong\model\Daily as DailyModel;
  10. use addons\qingdong\model\Message;
  11. use addons\qingdong\model\Comment;
  12. use think\DB;
  13. use think\Exception;
  14. use function EasyWeChat\Kernel\Support\get_client_ip;
  15. /**
  16. * 工作报告
  17. */
  18. class Daily extends Base {
  19. /**
  20. * @var \addons\qingdong\model\Daily
  21. */
  22. protected $model = null;
  23. public function _initialize() {
  24. parent::_initialize();
  25. $this->model = new DailyModel();
  26. }
  27. /**
  28. * 工作报告
  29. */
  30. public function index() {
  31. $this->request->filter(['strip_tags']);
  32. if ($this->request->isAjax()) {
  33. //0:全部 1:我负责的 2:下属负责的
  34. $type = input('type',0);
  35. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  36. switch($type){
  37. case 1:
  38. $staff = Staff::info();
  39. $wheres['create_staff_id'] = $staff->id;
  40. break;
  41. case 2:
  42. $wheres['create_staff_id'] = array('in',Staff::getLowerStaffId());
  43. break;
  44. default:
  45. $wheres['create_staff_id'] = array('in',Staff::getMyStaffIds());
  46. break;
  47. }
  48. $whereT=[];
  49. $staff_id=input('staff_id');
  50. if($staff_id){
  51. $whereT['create_staff_id']=$staff_id;
  52. }
  53. $staff_id=$this->_staff->id;
  54. $list = $this->model->where($where)->where($whereT)->where($wheres)
  55. ->where(function ($query) use ($staff_id,$wheres){
  56. $query->where($wheres)
  57. ->whereOr('','exp', Db::raw('FIND_IN_SET(' . $staff_id. ',reminds_id)'));
  58. })
  59. ->order($sort, $order)->with(['staff'])->paginate($limit);
  60. $row = $list->items();
  61. $result = array("total" => $list->total(), "rows" => $row);
  62. return json($result);
  63. }
  64. return $this->view->fetch();
  65. }
  66. /**
  67. * 添加
  68. */
  69. public function add()
  70. {
  71. if ($this->request->isPost()) {
  72. $params = $this->request->post("row/a");
  73. if ($params) {
  74. $params = $this->preExcludeFields($params);
  75. $result = false;
  76. Db::startTrans();
  77. try {
  78. $types = $params['type'];
  79. switch($types){
  80. case '日报':
  81. $typeinfo ='daily';
  82. break;
  83. case '周报':
  84. $typeinfo ='weekly';
  85. break;
  86. case '月报':
  87. $typeinfo ='monthly';
  88. break;
  89. case '季报':
  90. $typeinfo ='quarterly';
  91. break;
  92. case '年报':
  93. $typeinfo ='yearly';
  94. break;
  95. default:
  96. $typeinfo ='daily';
  97. break;
  98. }
  99. $form = Form::getDataValue($typeinfo);
  100. foreach($form as $k=>$v){
  101. if($v['component'] == 'uploadImage' || $v['component'] == 'uploadFile'){
  102. if(key_exists($v['id'],$params)){
  103. if($params[$v['id']]){
  104. $filearr = explode(',',$params[$v['id']]);
  105. $files ='';
  106. if($filearr){
  107. foreach($filearr as $ks=>$vs){
  108. $files = File::where(array('file_path|id'=>$vs))->order('id desc')->value('id').','.$files;
  109. }
  110. $params[$v['id']] = rtrim($files,',');
  111. }
  112. }
  113. }
  114. }elseif($v['component'] == 'select'){
  115. if(isset($v['config']['multiple']) && $v['config']['multiple'] == true){
  116. if(key_exists($v['id'],$params)){
  117. if($params[$v['id']]){
  118. $params[$v['id']] = implode(',',$params[$v['id']]);
  119. }
  120. }
  121. }
  122. }
  123. }
  124. $params['create_staff_id'] = $this->_staff->id;
  125. $result = $this->model::createDaily($params);
  126. Db::commit();
  127. } catch (Exception $e) {
  128. Db::rollback();
  129. $this->error($e->getMessage());
  130. }
  131. if ($result !== false) {
  132. $this->success();
  133. } else {
  134. $this->error(__('No rows were inserted'));
  135. }
  136. }
  137. $this->error(__('Parameter %s can not be empty', ''));
  138. }
  139. $type=input('type','daily');
  140. $data=[
  141. 'daily'=>'日报',
  142. 'weekly'=>'周报',
  143. 'monthly'=>'月报',
  144. 'quarterly'=>'季报',
  145. 'yearly'=>'年报',
  146. ];
  147. $this->assign('staff', Staff::where([])->column('name', 'id'));
  148. $this->assign('form_data', Form::getDataValue($type));
  149. $this->assign('type', $data[$type]??'日');
  150. $remind=Remind::where(['type'=>Remind::DAILY_TYPE])->find();
  151. $staff_ids=$remind['staff_ids']??'';
  152. $this->assign('staff_ids', $staff_ids);
  153. return $this->view->fetch();
  154. }
  155. /**
  156. * 工作报告详情
  157. */
  158. public function detail($ids = null) {
  159. $row = $this->model->with(['staff'])->where([
  160. 'id' => $ids
  161. ])->find();
  162. $row=$row->toArray();
  163. $row=array_merge($row,$row['other']);
  164. switch($row['type']){
  165. case '日报':
  166. $type = 'daily';
  167. break;
  168. case '周报':
  169. $type ='weekly';
  170. break;
  171. case '月报':
  172. $type = 'monthly';
  173. break;
  174. case '季报':
  175. $type = 'quarterly';
  176. break;
  177. case '年报':
  178. $type = 'yearly';
  179. break;
  180. default:
  181. $type = 'daily';
  182. break;
  183. }
  184. $form = Form::getDataValue($type,$row);
  185. foreach($form as $k=>$v){
  186. if($v['component'] == 'uploadImage' || $v['component'] == 'uploadFile'){
  187. if(key_exists($v['id'],$row)){
  188. if(isset($row[$v['id']]) && $row[$v['id']]){
  189. $whereT['id'] = array('in',$row[$v['id']]);
  190. $fileinfo = File::where($whereT)->field('id,name,file_path')->select();
  191. if($fileinfo){
  192. $row[$v['id']] = $fileinfo;
  193. }
  194. }
  195. }
  196. }
  197. }
  198. $this->assign('form_data',$form );
  199. $this->assign('row', $row);
  200. $this->assignconfig("idinfo", ['id' => $ids]);
  201. return $this->view->fetch();
  202. }
  203. /**
  204. * 添加评论
  205. */
  206. public function comment($ids=null) {
  207. if ($this->request->isPost()) {
  208. $content = input('content');
  209. if (empty($content)) {
  210. $this->error('评论内容不能为空');
  211. }
  212. $data = [
  213. 'relation_type' => Comment::DAILY_TYPE,
  214. 'relation_id' => $ids,
  215. 'staff_id' => $this->_staff->id,
  216. 'content' => $content,
  217. 'status' => 1,
  218. 'ip' => get_client_ip(),
  219. ];
  220. $commentModel = new Comment();
  221. $commentModel->save($data);
  222. $daily = DailyModel::get($ids);
  223. Message::addMessage(Message::COMMENT_TYPE, $ids, $daily->create_staff_id, $this->_staff->id);
  224. $this->success('评论成功');
  225. }
  226. return $this->view->fetch();
  227. }
  228. /**
  229. * 评论
  230. */
  231. public function comment_list() {
  232. $this->request->filter(['strip_tags']);
  233. if ($this->request->isAjax()) {
  234. $relation_id = input('relation_id','');
  235. $wheres['relation_id'] = $relation_id;
  236. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  237. $list = Comment::where($where)->where($wheres)->with(['staff','record'])->order($sort, $order)->paginate($limit);
  238. $row = $list->items();
  239. $result = array("total" => $list->total(), "rows" => $row);
  240. return json($result);
  241. }
  242. return $this->view->fetch();
  243. }
  244. }