Blame view

addons/antis/controller/ReceivablesPlan.php 3.17 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
  <?php

  

  namespace addons\antis\controller;

  

  use addons\antis\model\Message;

  use addons\antis\model\ReceivablesPlan as ReceivablesPlanModel;

  use addons\antis\model\Staff;

  use think\Db;

  use think\Exception;

  

  /**

   * 回款计划

   */

  class ReceivablesPlan extends StaffApi {

  	protected $noNeedLogin = [];

  	protected $noNeedRight = [];

  

  

  	//新增回款计划

  	public function addPlan() {

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

  

  		// 表单验证

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

              $this->error($result);

          }

  		if (ReceivablesPlanModel::where([

              'num'         => $params['num'],

              'contract_id' => $params['contract_id']

  		])->find()) {

  			$this->error('计划回款期数已存在');

  		}

  

  		Db::startTrans();

  		try {

  			ReceivablesPlanModel::createPlan($params);

  

  			Db::commit();

  		} catch (Exception $e) {

  			Db::rollback();

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

  		}

  		if ($result) {

  			$this->success('新增回款计划成功');

  		}

  	}

  

  

  	//获取回款计划列表

      public function getList()

      {

          $customer_id = input('customer_id');

          $contract_id = input('contract_id');

          $times = input('times');

          $staff_id = input('staff_id');

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

          $limit = input('limit');

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

          $where = [];

          if ($customer_id) {

              $where['customer_id'] = $customer_id;

          }

          if ($contract_id) {

              $where['contract_id'] = $contract_id;

          }

          if ($staff_id) {

              $where['owner_staff_id'] = $staff_id;

          } else {

  

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

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

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

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

              }else{

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

              }

  

          }

          if ($times) {//计划回款日期

              $times = explode(',', $times);

              $where['return_date'] = ['between', [$times[0], $times[1]]];

          }

          if($status !== null){

              $where['status'] = $status;

          }

  

          $list = ReceivablesPlanModel::where($where)->with(['contract', 'customer', 'createStaff'])

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

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

      }

  

  

  	//获取select回款计划列表

  	public function getSelectList() {

  		$contract_id          = input('contract_id');

  		$where                = [];

  		$where['contract_id'] = $contract_id;

  		$where['status']      = 0;

  		$list                 = ReceivablesPlanModel::where($where)->field('id,num')->select();

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

  	}

  

  

  	//回款详情

  	public function getDetail() {

  		$id       = input('id');

  		$customer = ReceivablesPlanModel::where(['id' => $id])->with(['contract', 'customer', 'createStaff'])->find();

  		//标记通知已读

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

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

  	}

  }