Seas.php 2.9 KB

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