Blame view

addons/antis/model/ReceivablesPlan.php 2.59 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
  <?php

  

  namespace addons\antis\model;

  

  use think\Exception;

  use think\Model;

  use traits\model\SoftDelete;

  

  /**

   *回款计划表

   */

  class ReceivablesPlan Extends Model {

  	use SoftDelete;

      // 表名,不含前缀

      protected $name = 'qingdong_receivables_plan';

  	// 开启自动写入时间戳字段

  	protected $autoWriteTimestamp = 'int';

  	// 定义时间戳字段名

  	protected $createTime = 'createtime';

  	protected $updateTime = 'updatetime';

  	protected $deleteTime = 'deletetime';

  

  

  	//创建回款计划

  	public static function createPlan($params) {

  		$staff                     = Staff::info();

  		$params['create_staff_id'] = $staff->id;

          $owner_staff_id = $staff->id;

          if($params['contract_id']){

              $owner_staff_id = Contract::where(array('id'=>$params['contract_id']))->value('owner_staff_id');

          }

          $params['owner_staff_id']  = $owner_staff_id;

  

  		$params['status']          = 0;

          if($params['remind']){

              $params['remind_date']=date('Y-m-d',strtotime("-{$params['remind']} day",

                  strtotime($params['return_date'])));

          }else{

              $params['remind_date']=$params['return_date'];

          }

  		$Model                     = new self;

          $result = $Model->allowField(true)->save($params);

  

  		if (false === $result) {

  			// 验证失败 输出错误信息

  			throw new Exception($Model->getError());

  		}

  

  		return true;

  	}

  //修改回款计划

      public static function updatePlan($map,$params) {

  

          if($params['remind']){

              $params['remind_date']=date('Y-m-d',strtotime("-{$params['remind']} day",

                  strtotime($params['return_date'])));

          }else{

              $params['remind_date']=$params['return_date'];

          }

          $Model                     = new self;

          $result = $Model->allowField(true)->save($params,$map);

  

          if (false === $result) {

              // 验证失败 输出错误信息

              throw new Exception($Model->getError());

          }

  

          return true;

      }

  

  	//合同

  	public function contract() {

  		return $this->hasOne(Contract::class, 'id', 'contract_id')->field('id,name,num,money');

  	}

  

  

  	//客户

  	public function customer() {

  		return $this->hasOne(Customer::class, 'id', 'customer_id')->field('id,name,subname');

  	}

  

  	//客户

  	public function createStaff() {

  		return $this->hasOne(Staff::class, 'id', 'create_staff_id')->field('id,name,img');

  	}

  	//客户

  	public function ownerStaff() {

  		return $this->hasOne(Staff::class, 'id', 'owner_staff_id')->field('id,name,img');

  	}

  

  }