Canlendar.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace app\admin\controller\qingdongams\canlendar;
  3. use addons\qingdongams\model\Staff;
  4. use app\admin\controller\qingdongams\Base;
  5. use addons\qingdongams\model\Event;
  6. use addons\qingdongams\model\Customer;
  7. use addons\qingdongams\model\Contacts;
  8. use addons\qingdongams\model\Contract;
  9. use addons\qingdongams\model\Leads;
  10. use think\DB;
  11. use fast\Tree;
  12. /**
  13. * 日程
  14. */
  15. class Canlendar extends Base {
  16. public function _initialize() {
  17. parent::_initialize();
  18. $this->model = new Event();
  19. }
  20. /**
  21. * 日程列表
  22. */
  23. public function index() {
  24. $this->request->filter(['strip_tags']);
  25. $need = input('need','');
  26. if ($this->request->isAjax()) {
  27. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  28. $wheres['type'] =1;
  29. $wheres['staff_id'] = ['in',Staff::getMyStaffIds()];
  30. if(isset($need) && $need == 'canlendar'){
  31. $wheres['staff_id'] = $this->_staff->id;
  32. $wheres['status'] = array('in','0,1');
  33. }
  34. if(isset($need) && $need == 'task'){
  35. $wheres['staff_id'] = $this->_staff->id;
  36. $wheres['status'] = array('in','0,1');
  37. $wheres['start_time'] = ['lt', date('Y-m-d', strtotime('+1 day'))];
  38. }
  39. $list = $this->model->where($where)->where($wheres)->order($sort, $order)->paginate($limit);
  40. $row = $list->items();
  41. $result = array("total" => $list->total(), "rows" => $row);
  42. return json($result);
  43. }
  44. return $this->view->fetch();
  45. }
  46. /**
  47. * 添加日程
  48. */
  49. public function add() {
  50. if ($this->request->isAjax()) {
  51. $data = $this->request->post('row/a');
  52. $staff = Staff::info();
  53. $data['staff_id'] = $staff->id;
  54. $result = $this->model->save($data);
  55. if (!$result) {
  56. $this->error('提交失败');
  57. }
  58. $this->success('提交成功');
  59. }
  60. $customer = Customer::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
  61. $this->view->assign("customer", $customer);
  62. return $this->view->fetch();
  63. }
  64. /**
  65. * 修改日程
  66. */
  67. public function edit($ids = null) {
  68. $map['id'] = $ids;
  69. if ($this->request->isAjax()) {
  70. $data = $this->request->post('row/a');
  71. $result = $this->model->save($data, $map);
  72. if (!$result) {
  73. $this->error('修改失败');
  74. }
  75. $this->success('修改成功');
  76. }
  77. $data = $this->model->where($map)->find();
  78. if($data['relation_type'] == 1){
  79. $customer = Customer::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
  80. }elseif($data['relation_type'] == 2){
  81. $customer = Contacts::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
  82. }elseif($data['relation_type'] == 3){
  83. $customer = Contract::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
  84. }elseif($data['relation_type'] == 4){
  85. $customer = Leads::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
  86. }else{
  87. $customer = Customer::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
  88. }
  89. $this->view->assign("customer", $customer);
  90. $this->view->assign("row", $data);
  91. return $this->view->fetch();
  92. }
  93. /**
  94. * 删除日程
  95. */
  96. public function del($ids = null) {
  97. if ($this->request->isAjax()) {
  98. $map['id'] = array('in', $ids);
  99. $result = $this->model->destroy($map);
  100. if (!$result) {
  101. $this->error('删除失败');
  102. }
  103. $this->success('删除成功');
  104. }
  105. return $this->view->fetch();
  106. }
  107. /**
  108. * 获取客户列表
  109. */
  110. public function customer(){
  111. $list = Customer::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
  112. $this->success('','',$list);
  113. }
  114. /**
  115. * 获取联系人列表
  116. */
  117. public function contacts(){
  118. $list = Contacts::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
  119. $this->success('','',$list);
  120. }
  121. /**
  122. * 获取合同列表
  123. */
  124. public function contract(){
  125. $list = Contract::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
  126. $this->success('','',$list);
  127. }
  128. /**
  129. * 获取线索列表
  130. */
  131. public function leads(){
  132. $list = Leads::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
  133. $this->success('','',$list);
  134. }
  135. }