Visa.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace app\admin\controller\massager;
  3. use app\admin\model\Area;
  4. use app\api\model\system\Message;
  5. use app\common\controller\Backend;
  6. /**
  7. * 异地签证
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Visa extends Backend
  12. {
  13. /**
  14. * Visa模型对象
  15. * @var \app\admin\model\massager\Visa
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\massager\Visa;
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. }
  24. protected $noNeedRight = ["check"];
  25. private function fetchWhere()
  26. {
  27. $admin = $this->auth->getUserInfo();
  28. if (!$admin)
  29. $this->error("error");
  30. $p_where = [];
  31. if (\E_ADMIN_TYPE::Store === $admin["type"]) {
  32. array_push($p_where, ["massager.store_id", "=", $admin["store_id"]]);
  33. } else if (\E_ADMIN_TYPE::Agency === $admin["type"]) {
  34. array_push($p_where, ["massager.city_code", "in", is_null($admin["city_codes"]) ? [] : explode(",", $admin["city_codes"])]);
  35. }
  36. return $p_where;
  37. }
  38. /**
  39. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  40. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  41. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  42. */
  43. /**
  44. * 查看
  45. */
  46. public function index()
  47. {
  48. //当前是否为关联查询
  49. $this->relationSearch = true;
  50. //设置过滤方法
  51. $this->request->filter(['strip_tags', 'trim']);
  52. $c_where = $this->fetchWhere();
  53. if ($this->request->isAjax()) {
  54. //如果发送的来源是Selectpage,则转发到Selectpage
  55. if ($this->request->request('keyField')) {
  56. return $this->c_selectpage($c_where);
  57. }
  58. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  59. $query = $this->model
  60. ->with(['massager'])
  61. ->where($where);
  62. foreach ($c_where as $item) {
  63. $query->where($item[0], $item[1], $item[2]);
  64. }
  65. $list = $query
  66. ->order($sort, $order)
  67. ->paginate($limit);
  68. foreach ($list as &$row) {
  69. $row->visible(['id', 'massager_id', 'old_area_code', 'new_area_code', 'description', 'status', 'updatetime']);
  70. $row->visible(['massager']);
  71. $row->getRelation('massager')->visible(['name']);
  72. }
  73. $rows = collection($list->items())->toArray();
  74. foreach ($rows as &$row) {
  75. $old_area = (new Area())->where("area_code", $row["old_area_code"])->find();
  76. $new_area = (new Area())->where("area_code", $row["new_area_code"])->find();
  77. $row["old_area_name"] = $old_area ? $old_area["mergename"] : null;
  78. $row["new_area_name"] = $new_area ? $new_area["mergename"] : null;
  79. }
  80. $result = array("total" => $list->total(), "rows" => $rows);
  81. return json($result);
  82. }
  83. return $this->view->fetch();
  84. }
  85. public function check($id = null, $check = null)
  86. {
  87. if (!$id || !$check)
  88. $this->error("参数错误!");
  89. $record = $this->model->where([
  90. "id" => $id,
  91. "status" => \E_MASSAGER_STATUS::Default,
  92. ])->find();
  93. if (!$record)
  94. $this->error("申请记录不存在!");
  95. $new_area = (new Area())->where([
  96. "area_code" => $record["new_area_code"],
  97. "use" => 1,
  98. "level" => 2
  99. ])->find();
  100. if (!$new_area)
  101. $this->error("申请迁入的地址不存在!");
  102. $is_pass = $check === "pass";
  103. $this->model->update([
  104. "updatetime" => time(),
  105. "status" => $is_pass ? "pass" : "reject"
  106. ], ["id" => $id]);
  107. if ($is_pass) {
  108. (new \app\admin\model\Massager())->update([
  109. "updatetime" => time(),
  110. "city_code" => $new_area["area_code"],
  111. "lng" => $record["lng"],
  112. "lat" => $record["lat"],
  113. ],
  114. ["id" => $record["massager_id"]]
  115. );
  116. }
  117. Message::sendSystemMessage(
  118. \E_IDENTITY_TYPE::Massager,
  119. ["to_massager_id" => $record["massager_id"]],
  120. "异地签证提醒",
  121. "您的异地签证申请已被管理员" . ($is_pass ? "通过!" : "拒绝!")
  122. );
  123. $this->success("审核成功!");
  124. }
  125. }