ReceivablesPlan.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace addons\qingdongams\model;
  3. use think\Exception;
  4. use think\Model;
  5. use traits\model\SoftDelete;
  6. /**
  7. *回款计划表
  8. */
  9. class ReceivablesPlan Extends Model {
  10. use SoftDelete;
  11. // 表名,不含前缀
  12. protected $name = 'qingdongams_receivables_plan';
  13. // 开启自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'int';
  15. // 定义时间戳字段名
  16. protected $createTime = 'createtime';
  17. protected $updateTime = 'updatetime';
  18. protected $deleteTime = 'deletetime';
  19. //创建回款计划
  20. public static function createPlan($params) {
  21. $staff = Staff::info();
  22. $params['create_staff_id'] = $staff->id;
  23. $owner_staff_id = $staff->id;
  24. if($params['contract_id']){
  25. $owner_staff_id = Contract::where(array('id'=>$params['contract_id']))->value('owner_staff_id');
  26. }
  27. $params['owner_staff_id'] = $owner_staff_id;
  28. $params['status'] = 0;
  29. if($params['remind']){
  30. $params['remind_date']=date('Y-m-d',strtotime("-{$params['remind']} day",
  31. strtotime($params['return_date'])));
  32. }else{
  33. $params['remind_date']=$params['return_date'];
  34. }
  35. $Model = new self;
  36. $result = $Model->allowField(true)->save($params);
  37. if (false === $result) {
  38. // 验证失败 输出错误信息
  39. throw new Exception($Model->getError());
  40. }
  41. return true;
  42. }
  43. //修改回款计划
  44. public static function updatePlan($map,$params) {
  45. if($params['remind']){
  46. $params['remind_date']=date('Y-m-d',strtotime("-{$params['remind']} day",
  47. strtotime($params['return_date'])));
  48. }else{
  49. $params['remind_date']=$params['return_date'];
  50. }
  51. $Model = new self;
  52. $result = $Model->allowField(true)->save($params,$map);
  53. if (false === $result) {
  54. // 验证失败 输出错误信息
  55. throw new Exception($Model->getError());
  56. }
  57. return true;
  58. }
  59. //合同
  60. public function contract() {
  61. return $this->hasOne(Contract::class, 'id', 'contract_id')->field('id,name,num,money');
  62. }
  63. //客户
  64. public function customer() {
  65. return $this->hasOne(Customer::class, 'id', 'customer_id')->field('id,name,subname');
  66. }
  67. //客户
  68. public function createStaff() {
  69. return $this->hasOne(Staff::class, 'id', 'create_staff_id')->field('id,name,img');
  70. }
  71. //客户
  72. public function ownerStaff() {
  73. return $this->hasOne(Staff::class, 'id', 'owner_staff_id')->field('id,name,img');
  74. }
  75. }