123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace app\admin\controller\qingdongams\canlendar;
- use addons\qingdongams\model\Staff;
- use app\admin\controller\qingdongams\Base;
- use addons\qingdongams\model\Event;
- use addons\qingdongams\model\Customer;
- use addons\qingdongams\model\Contacts;
- use addons\qingdongams\model\Contract;
- use addons\qingdongams\model\Leads;
- use think\DB;
- use fast\Tree;
- /**
- * 日程
- */
- class Canlendar extends Base {
- public function _initialize() {
- parent::_initialize();
- $this->model = new Event();
- }
- /**
- * 日程列表
- */
- public function index() {
- $this->request->filter(['strip_tags']);
- $need = input('need','');
- if ($this->request->isAjax()) {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $wheres['type'] =1;
- $wheres['staff_id'] = ['in',Staff::getMyStaffIds()];
- if(isset($need) && $need == 'canlendar'){
- $wheres['staff_id'] = $this->_staff->id;
- $wheres['status'] = array('in','0,1');
- }
- if(isset($need) && $need == 'task'){
- $wheres['staff_id'] = $this->_staff->id;
- $wheres['status'] = array('in','0,1');
- $wheres['start_time'] = ['lt', date('Y-m-d', strtotime('+1 day'))];
- }
- $list = $this->model->where($where)->where($wheres)->order($sort, $order)->paginate($limit);
- $row = $list->items();
- $result = array("total" => $list->total(), "rows" => $row);
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 添加日程
- */
- public function add() {
- if ($this->request->isAjax()) {
- $data = $this->request->post('row/a');
- $staff = Staff::info();
- $data['staff_id'] = $staff->id;
- $result = $this->model->save($data);
- if (!$result) {
- $this->error('提交失败');
- }
- $this->success('提交成功');
- }
- $customer = Customer::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
- $this->view->assign("customer", $customer);
- return $this->view->fetch();
- }
- /**
- * 修改日程
- */
- public function edit($ids = null) {
- $map['id'] = $ids;
- if ($this->request->isAjax()) {
- $data = $this->request->post('row/a');
- $result = $this->model->save($data, $map);
- if (!$result) {
- $this->error('修改失败');
- }
- $this->success('修改成功');
- }
- $data = $this->model->where($map)->find();
- if($data['relation_type'] == 1){
- $customer = Customer::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
- }elseif($data['relation_type'] == 2){
- $customer = Contacts::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
- }elseif($data['relation_type'] == 3){
- $customer = Contract::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
- }elseif($data['relation_type'] == 4){
- $customer = Leads::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
- }else{
- $customer = Customer::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
- }
- $this->view->assign("customer", $customer);
- $this->view->assign("row", $data);
- return $this->view->fetch();
- }
- /**
- * 删除日程
- */
- public function del($ids = null) {
- if ($this->request->isAjax()) {
- $map['id'] = array('in', $ids);
- $result = $this->model->destroy($map);
- if (!$result) {
- $this->error('删除失败');
- }
- $this->success('删除成功');
- }
- return $this->view->fetch();
- }
- /**
- * 获取客户列表
- */
- public function customer(){
- $list = Customer::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
- $this->success('','',$list);
- }
- /**
- * 获取联系人列表
- */
- public function contacts(){
- $list = Contacts::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
- $this->success('','',$list);
- }
- /**
- * 获取合同列表
- */
- public function contract(){
- $list = Contract::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
- $this->success('','',$list);
- }
- /**
- * 获取线索列表
- */
- public function leads(){
- $list = Leads::where(['owner_staff_id'=>['in',Staff::getMyStaffIds()]])->field('id,name')->select();
- $this->success('','',$list);
- }
- }
|