Setting.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 客户模块设置
  4. // +----------------------------------------------------------------------
  5. // | Author: Michael_xu | gengxiaoxu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace addons\qingdong\controller;
  8. use addons\qingdong\model\Customer;
  9. use addons\qingdong\model\Staff;
  10. /**
  11. * 客户模块设置
  12. */
  13. class Setting extends StaffApi
  14. {
  15. /**
  16. * 获取团队成员
  17. */
  18. public function team()
  19. {
  20. $id = input('id');
  21. $customer = Customer::get($id);
  22. if (empty($customer)) {
  23. $this->error('客户不存在');
  24. }
  25. $owner_staff = Staff::where(['id' => $customer->owner_staff_id])->find();
  26. $rw_staffs = Staff::where(['id' => ['in', explode(',', $customer->rw_staff_id)]])->select();
  27. $ro_staffs = Staff::where(['id' => ['in', explode(',', $customer->ro_staff_id)]])->select();
  28. $staffs = [];
  29. if ($owner_staff) {
  30. $staffs[] = [
  31. 'id' => $owner_staff->id,
  32. 'name' => $owner_staff->name,
  33. 'img' => $owner_staff->img,
  34. 'post' => $owner_staff->post,
  35. 'mobile' => $owner_staff->mobile,
  36. 'roles' => 1,
  37. 'is_edit' => 1,
  38. ];
  39. }
  40. foreach ($rw_staffs as $v) {
  41. $staffs[] = [
  42. 'id' => $v->id,
  43. 'name' => $v->name,
  44. 'img' => $v->img,
  45. 'post' => $v->post,
  46. 'mobile' => $v->mobile,
  47. 'roles' => 2,
  48. 'is_edit' => 1,
  49. ];
  50. }
  51. foreach ($ro_staffs as $v) {
  52. $staffs[] = [
  53. 'id' => $v->id,
  54. 'name' => $v->name,
  55. 'img' => $v->img,
  56. 'post' => $v->post,
  57. 'mobile' => $v->mobile,
  58. 'roles' => 2,
  59. 'is_edit' => 0,
  60. ];
  61. }
  62. $this->success('请求成功', $staffs);
  63. }
  64. /**
  65. * 修改团队成员
  66. */
  67. public function editShowStaff()
  68. {
  69. $id = input('id');
  70. $staff = input('staff/a');
  71. $model = Customer::get($id);
  72. if (empty($model)) {
  73. $this->error('客户不存在');
  74. }
  75. $ro_staff_id = [];
  76. $rw_staff_id = [];
  77. foreach ($staff as $v) {
  78. if ($v['is_edit'] == 1) {
  79. $rw_staff_id[] = $v['id'];
  80. } else {
  81. $ro_staff_id[] = $v['id'];
  82. }
  83. }
  84. $ro_staff_id = array_diff($ro_staff_id, $rw_staff_id);
  85. $rw_staff_id=implode(',', $rw_staff_id);
  86. $ro_staff_id=implode(',', $ro_staff_id);
  87. $result = $model->save(['rw_staff_id' => ",{$rw_staff_id},",
  88. 'ro_staff_id' => ",{$ro_staff_id},"]);
  89. if ($result === false) {
  90. $this->error('修改失败');
  91. }
  92. $this->success('修改成功');
  93. }
  94. }