Blame view

addons/qingdong/controller2/Report.php 3.15 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
  <?php

  

  namespace addons\qingdong\controller;

  

  

  /**

   * 报备审批

   */

  

  class Report extends StaffApi

  {

      protected $noNeedLogin = ['*'];

  

  

      public function listReport(){

  

          $param = $this->request->param();

  

          $ReportModel = new \addons\qingdong\model\Report();

  

          //$where = [];

          if($param['type']==1){

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

          }elseif($param['type']==2){

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

          }else{

              $where = [];

          }

  

          $list = $ReportModel->with('staff')->where($where)->select();

  

          $this->success('报备列表',$list);

  

      }

  

  

      //添加

      public function addReport(){

  

          $param = $this->request->param();

  

          $ReportModel = new \addons\qingdong\model\Report();

  

          if(empty($param['business_name']) || empty($param['business_city']) || empty($param['company_name']) || empty($param['contacts_name']) || empty($param['contacts_mobile'])){

              $this->error('信息不完整,请完善填写信息');

          }

  

          $data = [

              'business_name'=>$param['business_name'],

              'business_city'=>$param['business_city'],

              'company_name'=>$param['company_name'],

              'contacts_name'=>$param['contacts_name'],

              'contacts_mobile'=>$param['contacts_mobile'],

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

              'status'=>1

          ];

  

          $res = $ReportModel->save($data);

  

          if($res){

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

          }

          $this->error('添加失败');

  

      }

  

      //审批

      public function approve(){

  

          $param = $this->request->param();

  

          $ReportModel = new \addons\qingdong\model\Report();

          $cusModel = new \addons\qingdong\model\Customer();

          $busModel = new \addons\qingdong\model\Business();

  

          $find = $ReportModel->where('id',$param['id'])->find();

  

          if($param['type'] == 1 && $find){

              $cus_data = [

                  'name'=> $find['company_name'],

                  'main_zxfpre'=>$find['contacts_name'],

                  'mobile'=>$find['contacts_mobile'],

                  'create_staff_id'=>$find['staff_id'],

                  'owner_staff_id'=>$find['staff_id'],

                  'receivetime'=>time(),

                  'follow'=>'初次接触',

                  'source'=>'行业活动',

                  'industry'=>'普通客户',

                  'level'=>5

              ];

              $result = $cusModel::createCustomer($cus_data);

  

              $bus_data = [

  

                  'customer_id'=>$result,

                  'name'=>$find['business_name'],

                  'create_staff_id'=>$find['staff_id'],

                  'owner_staff_id'=>$find['staff_id'],

              ];

  

              $busModel::createBusiness($bus_data);

  

              $find->status = 2;

              $find->save();

  

          }elseif ($param['type'] == 2 && $find){

              $find->status = 3;

              $find->save();

          }else{

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

          }

          $this->success('操作成功');

      }

  

  

  

  

  }