Seas.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\admin\controller\qingdong\customer;
  3. use addons\qingdong\model\Staff;
  4. use app\admin\controller\qingdong\Base;
  5. use app\common\library\Auth;
  6. use think\Db;
  7. use think\Exception;
  8. /**
  9. * 公海
  10. * 操作文档:https://doc.fastadmin.net/qingdong
  11. * 软件介绍:https://www.fastadmin.net/store/qingdong.html
  12. * 售后微信:qingdong_crm
  13. */
  14. class Seas extends Base {
  15. protected $relationSearch = true;
  16. protected $searchFields = 'id,name';
  17. /**
  18. * @var \addons\qingdong\model\Customer
  19. */
  20. protected $model = null;
  21. public function _initialize() {
  22. parent::_initialize();
  23. $this->model = new \addons\qingdong\model\Customer;
  24. }
  25. /**
  26. * 查看
  27. */
  28. public function index() {
  29. $this->request->filter(['strip_tags', 'trim']);
  30. if ($this->request->isAjax()) {
  31. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  32. $order = 'sea_time desc';
  33. //公海权限
  34. $rules=Staff::getStaffRule('seas');
  35. $list = $this->model->where($where)
  36. ->where(function ($query) use ($rules){
  37. foreach ($rules as $rule) {
  38. $query->whereOr(['seas_id'=>['like',"%,{$rule},%"]]);
  39. }
  40. })
  41. ->where('owner_staff_id is null or owner_staff_id = 0')->order($sort, $order) ->paginate($limit);
  42. $result = array("total" => $list->total(), "rows" => $list->items());
  43. return json($result);
  44. }
  45. return $this->view->fetch();
  46. }
  47. /**
  48. * 添加
  49. */
  50. public function add() {
  51. if ($this->request->isPost()) {
  52. $params = $this->request->post("row/a");
  53. if ($params) {
  54. $params = $this->preExcludeFields($params);
  55. $result = false;
  56. Db::startTrans();
  57. try {
  58. $result = $this->model->allowField(true)->save($params);
  59. Db::commit();
  60. } catch (Exception $e) {
  61. Db::rollback();
  62. $this->error($e->getMessage());
  63. }
  64. if ($result !== false) {
  65. $this->success();
  66. } else {
  67. $this->error(__('No rows were inserted'));
  68. }
  69. }
  70. $this->error(__('Parameter %s can not be empty', ''));
  71. }
  72. return $this->view->fetch();
  73. }
  74. /**
  75. * 公海详情
  76. */
  77. public function detail($ids=null){
  78. $row=$this->model->where(['id'=>$ids])->find();
  79. $this->assign('row',$row);
  80. $this->assign('ids',$ids);
  81. return $this->view->fetch();
  82. }
  83. /**
  84. * 删除
  85. */
  86. public function del($ids = "") {
  87. if (!$this->request->isPost()) {
  88. $this->error(__("Invalid parameters"));
  89. }
  90. $ids = $ids ? $ids : $this->request->post("ids");
  91. $row = $this->model->get($ids);
  92. $this->modelValidate = true;
  93. if (!$row) {
  94. $this->error(__('No Results were found'));
  95. }
  96. Auth::instance()->delete($row['id']);
  97. $this->success();
  98. }
  99. }