| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace app\admin\controller\massager;
- use app\admin\model\Area;
- use app\api\model\system\Message;
- use app\common\controller\Backend;
- /**
- * 异地签证
- *
- * @icon fa fa-circle-o
- */
- class Visa extends Backend
- {
- /**
- * Visa模型对象
- * @var \app\admin\model\massager\Visa
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\massager\Visa;
- $this->view->assign("statusList", $this->model->getStatusList());
- }
- protected $noNeedRight = ["check"];
- private function fetchWhere()
- {
- $admin = $this->auth->getUserInfo();
- if (!$admin)
- $this->error("error");
- $p_where = [];
- if (\E_ADMIN_TYPE::Store === $admin["type"]) {
- array_push($p_where, ["massager.store_id", "=", $admin["store_id"]]);
- } else if (\E_ADMIN_TYPE::Agency === $admin["type"]) {
- array_push($p_where, ["massager.city_code", "in", is_null($admin["city_codes"]) ? [] : explode(",", $admin["city_codes"])]);
- }
- return $p_where;
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
- * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 查看
- */
- public function index()
- {
- //当前是否为关联查询
- $this->relationSearch = true;
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- $c_where = $this->fetchWhere();
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->c_selectpage($c_where);
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $query = $this->model
- ->with(['massager'])
- ->where($where);
- foreach ($c_where as $item) {
- $query->where($item[0], $item[1], $item[2]);
- }
- $list = $query
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as &$row) {
- $row->visible(['id', 'massager_id', 'old_area_code', 'new_area_code', 'description', 'status', 'updatetime']);
- $row->visible(['massager']);
- $row->getRelation('massager')->visible(['name']);
- }
- $rows = collection($list->items())->toArray();
- foreach ($rows as &$row) {
- $old_area = (new Area())->where("area_code", $row["old_area_code"])->find();
- $new_area = (new Area())->where("area_code", $row["new_area_code"])->find();
- $row["old_area_name"] = $old_area ? $old_area["mergename"] : null;
- $row["new_area_name"] = $new_area ? $new_area["mergename"] : null;
- }
- $result = array("total" => $list->total(), "rows" => $rows);
- return json($result);
- }
- return $this->view->fetch();
- }
- public function check($id = null, $check = null)
- {
- if (!$id || !$check)
- $this->error("参数错误!");
- $record = $this->model->where([
- "id" => $id,
- "status" => \E_MASSAGER_STATUS::Default,
- ])->find();
- if (!$record)
- $this->error("申请记录不存在!");
- $new_area = (new Area())->where([
- "area_code" => $record["new_area_code"],
- "use" => 1,
- "level" => 2
- ])->find();
- if (!$new_area)
- $this->error("申请迁入的地址不存在!");
- $is_pass = $check === "pass";
- $this->model->update([
- "updatetime" => time(),
- "status" => $is_pass ? "pass" : "reject"
- ], ["id" => $id]);
- if ($is_pass) {
- (new \app\admin\model\Massager())->update([
- "updatetime" => time(),
- "city_code" => $new_area["area_code"],
- "lng" => $record["lng"],
- "lat" => $record["lat"],
- ],
- ["id" => $record["massager_id"]]
- );
- }
- Message::sendSystemMessage(
- \E_IDENTITY_TYPE::Massager,
- ["to_massager_id" => $record["massager_id"]],
- "异地签证提醒",
- "您的异地签证申请已被管理员" . ($is_pass ? "通过!" : "拒绝!")
- );
- $this->success("审核成功!");
- }
- }
|