Blame view

application/admin/controller/antis/customer/Seas.php 2.81 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  <?php

  

  namespace app\admin\controller\antis\customer;

  

  use addons\antis\model\Staff;

  use app\admin\controller\antis\Base;

  use app\common\library\Auth;

  use think\Db;

  use think\Exception;

  

  /**

   * 公海

   * 操作文档:https://doc.fastadmin.net/antis

   * 软件介绍:https://www.fastadmin.net/store/antis.html

   * 售后微信:qingdong_crm

   */

  class Seas extends Base {

  	protected $relationSearch = true;

  	protected $searchFields   = 'id,name';

  	/**

  	 * @var \addons\antis\model\Customer

  	 */

  	protected $model = null;

  

  

  	public function _initialize() {

  		parent::_initialize();

  		$this->model = new \addons\antis\model\Customer;

  	}

  

  

  	/**

  	 * 查看

  	 */

  	public function index() {

  		$this->request->filter(['strip_tags', 'trim']);

  		if ($this->request->isAjax()) {

  

  			list($where, $sort, $order, $offset, $limit) = $this->buildparams();

              $order = 'sea_time desc';

              //公海权限

              $rules=Staff::getStaffRule('seas');

              $list = $this->model->where($where)

                  ->where(function ($query) use ($rules){

                      foreach ($rules as $rule) {

                          $query->whereOr(['seas_id'=>['like',"%,{$rule},%"]]);

                      }

                  })

                  ->where('owner_staff_id is null or owner_staff_id = 0')->order($sort, $order) ->paginate($limit);

              $result = array("total" => $list->total(), "rows" => $list->items());

  

  			return json($result);

  		}

  

  		return $this->view->fetch();

  	}

  

  

  	/**

  	 * 添加

  	 */

  	public function add() {

  		if ($this->request->isPost()) {

  			$params = $this->request->post("row/a");

  			if ($params) {

  				$params = $this->preExcludeFields($params);

  

  				$result = false;

  				Db::startTrans();

  				try {

  					$result = $this->model->allowField(true)->save($params);

  					Db::commit();

  				} catch (Exception $e) {

  					Db::rollback();

  					$this->error($e->getMessage());

  				}

  				if ($result !== false) {

  					$this->success();

  				} else {

  					$this->error(__('No rows were inserted'));

  				}

  			}

  			$this->error(__('Parameter %s can not be empty', ''));

  		}

  		return $this->view->fetch();

  	}

  

      /**

       * 公海详情

       */

  	public function detail($ids=null){

  		$row=$this->model->where(['id'=>$ids])->find();

  		$this->assign('row',$row);

  		$this->assign('ids',$ids);

  		return $this->view->fetch();

  	}

  

  	/**

  	 * 删除

  	 */

  	public function del($ids = "") {

  		if (!$this->request->isPost()) {

  			$this->error(__("Invalid parameters"));

  		}

  		$ids                 = $ids ? $ids : $this->request->post("ids");

  		$row                 = $this->model->get($ids);

  		$this->modelValidate = true;

  		if (!$row) {

  			$this->error(__('No Results were found'));

  		}

  		Auth::instance()->delete($row['id']);

  		$this->success();

  	}

  }