Blame view

addons/antis/controller/Event.php 6.72 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
  <?php

  

  namespace addons\antis\controller;

  

  use addons\antis\model\Event as EventModel;

  use addons\antis\model\File;

  use addons\antis\model\Form;

  use addons\antis\model\StaffSignIn;

  use addons\antis\model\Message;

  use addons\antis\model\Staff;

  use think\Db;

  use think\Exception;

  

  /**

   * 日程接口

   */

  class Event extends StaffApi

  {

      protected $noNeedLogin = [];

      protected $noNeedRight = [];

  

  

      //获取日程

      public function getEvent()

      {

          //开始时间

          $start_day = input('start_day');

          //结束时间

          $end_day = input('end_day');;

          if (empty($start_day) || empty($end_day)) {

              $this->error('开始时间或结束时间不能为空');

          }

          if ($end_day < $start_day) {

              $this->error('开始时间不能小于结束时间');

          }

          $this->success('请求成功', EventModel::getTimeList($start_day, $end_day));

      }

  

  

      //添加日程

      public function addEvent()

      {

          $params = $this->request->post();

          // 表单验证

          if (($result = $this->qingdongValidate($params, get_class(), 'create')) !== true) {

              $this->error($result);

          }

          Db::startTrans();

          try {

              $params['type'] = 1;//日程

              $result = EventModel::createEvent($params);

              Db::commit();

          } catch (Exception $e) {

              Db::rollback();

              $this->error($e->getMessage());

          }

          if ($result) {

              $this->success('添加日程成功');

          }

      }

  

  

      //变更状态

      public function changeStatus()

      {

          $id = input('id');

          $status = input('status', 0);

          if (empty($id)) {

              $this->error('参数错误');

          }

          Db::startTrans();

          try {

              EventModel::changeStatus($id, $status);

              Db::commit();

          } catch (Exception $e) {

              Db::rollback();

              $this->error($e->getMessage());

          }

          $this->success('变更成功');

      }

  

  

      //

      public function getList()

      {

          $relation_type = input('relation_type', '', 'intval');// 1客户 2联系人 3合同 4线索

          $relation_id = input('relation_id', '', 'intval');

          $limit = input("limit/d", 10);

          $where = [];

          $where['relation_type'] = $relation_type;

          $where['relation_id'] = $relation_id;

          $where['staff_id'] = $this->auth->id;

          $records = EventModel::where($where)->with(['staff'])->field('id,staff_id,type,title,start_time,end_time,status,auto_end,level,remindtype,remark,color,createtime')->order('id desc')->paginate($limit);

          $this->success('请求成功', $records);

      }

  

  

      //添加签到

      public function addSign()

      {

          $params = $this->request->post();

          $location = input('location');

          $lng = input('lng');

          $lat = input('lat');

          $files = input('file_ids');

          $customer_id = input('customer_id');

          $content = input('content');

          if (empty($lng) || empty($lat)) {

              $this->error('地理位置不能为空');

          }

  

          //自定义字段

          $other = [];

          foreach ($params as $name => $val) {

              if (strstr( $name,'other_') !== false) {

                  if(is_array($val)){

                      $other[$name] = implode(',',$val);

                  }else{

                      $other[$name] = $val;

                  }

                  unset($params[$name]);

              }

          }

  

          $data = [

              'location' => $location,

              'lng' => $lng,

              'lat' => $lat,

              'file_ids' => $files,

              'customer_id' => $customer_id,

              'staff_id' => $this->auth->id,

              'other' => json_encode($other, JSON_UNESCAPED_UNICODE)

          ];

          $model = new StaffSignIn();

          if ($result = $model->save($data)) {

              $lastId = $model->getLastInsID();

              //通知上级

              Message::addMessage(Message::SIGN_TYPE, $lastId, $this->auth->parent_id, $this->auth->id);

              $this->success('签到成功');

          }

          $this->error('签到失败');

      }

  

  

      //获取签到信息

      public function getSign()

      {

          $customer_id = input('customer_id', 0, 'intval');

          $limit = input("limit/d", 10);

          $where = [];

          $type       = input('type', 0);// 0 全部 1 我创建 2 下属创建

  

          if ($type == 1) {//我的客户

              $where['staff_id'] = $this->auth->id;

          } elseif ($type == 2) {//下属负责的客户

              $where['staff_id'] = ['in', Staff::getLowerStaffId()];

          }else{

              $where['staff_id'] = ['in', Staff::getMyStaffIds()];

          }

          if ($customer_id) {

              $where['customer_id'] = $customer_id;

          }

          $staffSign = StaffSignIn::where($where)->with(['staff', 'customer'])

              ->order('id desc')->paginate($limit);

          //标记通知已读

          Message::setRead(Message::SIGN_TYPE,0, $this->auth->id);

          $this->success('请求成功', $staffSign);

      }

  

      /**

       * 获取签到详情

       */

      public function getSignDetail(){

          $id = input('id', 0, 'intval');

  

          $staffSign = StaffSignIn::where(['id'=>$id])->with(['staff', 'customer'])->find();

          if(empty($staffSign)){

              $this->error('数据不存在');

          }

          if($staffSign['other']){

              $other = json_decode($staffSign['other'],true);

              $form = Form::getDataValue('signin');

              foreach($form as $k=>$v){

                  if($v['component'] == 'uploadImage' || $v['component'] == 'uploadFile'){

                      $other[$v['id'].'_str'] = '';

                      if(key_exists($v['id'],$other)){

                          if(isset($other[$v['id']]) && $other[$v['id']]){

                              $whereT['id'] = array('in',$other[$v['id']]);

                              $fileinfo = File::where($whereT)->field('id,name,file_path,save_name')->select();

                              if($fileinfo){

                                  $other[$v['id']] = $fileinfo;

                                  $fileinfodata = '';

                                  foreach($fileinfo as $kss=>$vss){

                                      $fileinfodata = $vss['save_name'].','.$fileinfodata;

                                  }

                                  $other[$v['id'].'_str'] = rtrim($fileinfodata,',');

                              }

                          }

                      }

                  }

              }

              $staffSign['other'] = $other;

          }

          $this->success('请求成功',$staffSign);

      }

  }