ReceivablesPlan.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace addons\qingdongams\controller;
  3. use addons\qingdongams\model\Message;
  4. use addons\qingdongams\model\ReceivablesPlan as ReceivablesPlanModel;
  5. use addons\qingdongams\model\Staff;
  6. use think\Db;
  7. use think\Exception;
  8. /**
  9. * 回款计划
  10. */
  11. class ReceivablesPlan extends StaffApi {
  12. protected $noNeedLogin = [];
  13. protected $noNeedRight = [];
  14. //新增回款计划
  15. public function addPlan() {
  16. $params = $this->request->post();
  17. // 表单验证
  18. if (($result = $this->qingdongamsValidate($params, get_class(), 'create')) !== true) {
  19. $this->error($result);
  20. }
  21. if (ReceivablesPlanModel::where([
  22. 'num' => $params['num'],
  23. 'contract_id' => $params['contract_id']
  24. ])->find()) {
  25. $this->error('计划回款期数已存在');
  26. }
  27. Db::startTrans();
  28. try {
  29. ReceivablesPlanModel::createPlan($params);
  30. Db::commit();
  31. } catch (Exception $e) {
  32. Db::rollback();
  33. $this->error($e->getMessage());
  34. }
  35. if ($result) {
  36. $this->success('新增回款计划成功');
  37. }
  38. }
  39. //获取回款计划列表
  40. public function getList()
  41. {
  42. $customer_id = input('customer_id');
  43. $contract_id = input('contract_id');
  44. $times = input('times');
  45. $staff_id = input('staff_id');
  46. $status = input('status', null);
  47. $limit = input('limit');
  48. $type = input('type',0);
  49. $where = [];
  50. if ($customer_id) {
  51. $where['customer_id'] = $customer_id;
  52. }
  53. if ($contract_id) {
  54. $where['contract_id'] = $contract_id;
  55. }
  56. if ($staff_id) {
  57. $where['owner_staff_id'] = $staff_id;
  58. } else {
  59. if ($type == 1) {//我的客户
  60. $where['owner_staff_id'] = $this->auth->id;
  61. } elseif ($type == 2) {//下属负责的客户
  62. $where['owner_staff_id'] = ['in', Staff::getLowerStaffId()];
  63. }else{
  64. $where['owner_staff_id'] = ['in', Staff::getMyStaffIds()];
  65. }
  66. }
  67. if ($times) {//计划回款日期
  68. $times = explode(',', $times);
  69. $where['return_date'] = ['between', [$times[0], $times[1]]];
  70. }
  71. if($status !== null){
  72. $where['status'] = $status;
  73. }
  74. $list = ReceivablesPlanModel::where($where)->with(['contract', 'customer', 'createStaff'])
  75. ->order('id desc')->paginate($limit);
  76. $this->success('请求成功', $list);
  77. }
  78. //获取select回款计划列表
  79. public function getSelectList() {
  80. $contract_id = input('contract_id');
  81. $where = [];
  82. $where['contract_id'] = $contract_id;
  83. $where['status'] = 0;
  84. $list = ReceivablesPlanModel::where($where)->select();
  85. $this->success('请求成功', $list);
  86. }
  87. //回款详情
  88. public function getDetail() {
  89. $id = input('id');
  90. $customer = ReceivablesPlanModel::where(['id' => $id])->with(['contract', 'customer', 'createStaff'])->find();
  91. //标记通知已读
  92. Message::setRead(Message::PLAN_TYPE, $id, $this->auth->id);
  93. $this->success('请求成功', $customer);
  94. }
  95. }