model = new \app\admin\model\massager\Massager; $this->view->assign("genderList", $this->model->getGenderList()); $this->view->assign("levelList", $this->model->getLevelList()); $this->view->assign("statusList", $this->model->getStatusList()); $typeList = $this->model->getTypeList(); $admin = $this->auth->getUserInfo(); if ($admin && \E_ADMIN_TYPE::Store === $admin["type"]) { $typeList = ['store' => __('Store')]; } $this->view->assign("typeList", $typeList); } 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(['store', 'parent']) ->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_card_images', 'real_name_auth', 'health_image', 'police_certificate_image', 'emergency_contact_name', 'emergency_contact_mobile', 'emergency_contact_relation', 'wechat_no', 'id', 'name', 'photo_images', 'gender', 'date_of_birth', 'status', 'type', 'service_ids', 'free_travel', 'weight', 'updatetime', 'interior_score', 'negative_count', 'fixed_profit_rate']); $row->visible(['store']); $row->getRelation('store')->visible(['name']); $row->visible(['parent']); $row->getRelation('parent')->visible(['name']); } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } public function add() { if (false === $this->request->isPost()) { return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); if (isset($params["fixed_profit_rate"])) { if ($params["fixed_profit_rate"] < 0 || $params["fixed_profit_rate"] > 90) $this->error("固定分润比例必须在0~90之间"); } if (isset($params["area_id"]) && $params["area_id"] > 0) { $area = (new Area())->where([ "id" => $params["area_id"], "use" => 1, "level" => 2, ])->find(); if (!$area) $this->error("地区选择不正确"); $params["city_code"] = $area["area_code"]; $params["lng"] = $area["lng"]; $params["lat"] = $area["lat"]; } else { $this->error("地区选择不正确"); } if (strlen($params["password"]) == 0) unset($params["password"]); else $params["password"] = md5($params["password"]); if (!isset($params["mobile"]) || strlen($params["mobile"]) !== 11) $this->error("手机号码错误"); $m = $this->model->where("mobile", $params["mobile"])->find(); if ($m) { $this->error("手机号码已经存在!"); } if ($this->dataLimit && $this->dataLimitFieldAutoFill) { $params[$this->dataLimitField] = $this->auth->id; } $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; $this->model->validateFailException()->validate($validate); } $result = $this->model->allowField(true)->save($params); Db::commit(); } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result === false) { $this->error(__('No rows were inserted')); } $this->success(); } public function edit($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } if (false === $this->request->isPost()) { $this->view->assign('row', $row); return $this->view->fetch(); } $params = $this->request->post('row/a'); if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } $params = $this->preExcludeFields($params); if (isset($params["fixed_profit_rate"])) { if ($params["fixed_profit_rate"] < 0 || $params["fixed_profit_rate"] > 90) $this->error("固定分润比例必须在0~90之间"); } if (isset($params["area_id"]) && $params["area_id"] > 0) { if (is_null($row['lng']) && is_null($row["lat"])) { $area = (new Area())->where([ "id" => $params["area_id"], "use" => 1, "level" => 2, ])->find(); if (!$area) $this->error("地区选择不正确"); $params["city_code"] = $area["area_code"]; $params["lng"] = $area["lng"]; $params["lat"] = $area["lat"]; } } else { $this->error("地区选择不正确"); } if (strlen($params["password"]) == 0) unset($params["password"]); else $params["password"] = md5($params["password"]); if (isset($params["status"]) && $params["status"] != \E_MASSAGER_STATUS::Normal) { (new MassagerActionService())->workClockIn($row->id, true); } $result = false; Db::startTrans(); try { //是否采用模型验证 if ($this->modelValidate) { $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } $result = $row->allowField(true)->save($params); Db::commit(); } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } public function check($id = null, $check = null) { if (!$id || !$check) $this->error("参数错误!"); $massager = $this->model->where([ "id" => $id, "status" => \E_MASSAGER_STATUS::Checking, ])->find(); if (!$massager) $this->error("申请记录不存在!"); $is_pass = $check === "pass"; $this->model->update([ "updatetime" => time(), "status" => $is_pass ? \E_MASSAGER_STATUS::Normal : \E_MASSAGER_STATUS::Hidden ], ["id" => $id]); Message::sendSystemMessage( \E_IDENTITY_TYPE::Massager, ["to_massager_id" => $id], "助教审核", "您的申请已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); $switch = false;//config("site.invite_grant_switch"); if ($switch && $is_pass && $massager["parent_id"] > 0) { $mWalletModel = new Wallet(); $parent = $this->model->get($massager["parent_id"]); if ($parent) { $parent_wallet = $mWalletModel->getWallet($parent->id); $mobile_check_pass = config("site.mobile_check_pass"); (new \app\admin\model\massager\Bill())->save([ "massager_id" => $parent->id, "currency_type" => \E_USER_BILL_CURRENCY_TYPE::Money, "change_type" => \E_M_BILL_CHANGE_TYPE::ChannelIncome, "change" => $mobile_check_pass, "before" => $parent_wallet["profit_amount"], "after" => $parent_wallet["profit_amount"] + $mobile_check_pass, "reason" => "电话审核通过发放奖励", "relation_no" => null, "createtime" => time() ]); if ($parent_wallet) { $mWalletModel->where("id", $parent_wallet->id)->setInc("profit_amount", $mobile_check_pass); } } } $valid = TencentCloudService::tencent_cloud_sms_send(TencentCloudService::$MASSAGE_APPLY, $massager["mobile"], [$is_pass ? "通过!" : "拒绝!"]); if ($valid->code()) { $this->success("审核成功!"); } $this->error($valid->msg()); } public function real_name_auth($id = null, $check = null) { if (!$id || !$check) $this->error("参数错误!"); $massager = $this->model->where([ "id" => $id, "status" => \E_MASSAGER_STATUS::Normal, "real_name_auth" => \E_BASE_STATUS::Default ])->find(); if (!$massager) $this->error("申请记录不存在!"); $is_pass = $check === "pass"; $this->model->update([ "updatetime" => time(), "real_name_auth" => $is_pass ? "pass" : "reject" ], ["id" => $id]); Message::sendSystemMessage( \E_IDENTITY_TYPE::Massager, ["to_massager_id" => $id], "线下面试", "您的线下面试已被管理员" . ($is_pass ? "通过!" : "拒绝!") ); $switch = false;//config("site.invite_grant_switch"); if ($switch && $is_pass && $massager["parent_id"] > 0) { $mWalletModel = new Wallet(); $parent = $this->model->get($massager["parent_id"]); if ($parent) { $parent_wallet = $mWalletModel->getWallet($parent->id); $real_name_check_pass = config("site.real_name_check_pass"); (new \app\admin\model\massager\Bill())->save([ "massager_id" => $parent->id, "currency_type" => \E_USER_BILL_CURRENCY_TYPE::Money, "change_type" => \E_M_BILL_CHANGE_TYPE::ChannelIncome, "change" => $real_name_check_pass, "before" => $parent_wallet["profit_amount"], "after" => $parent_wallet["profit_amount"] + $real_name_check_pass, "reason" => "线下面试通过发放奖励", "relation_no" => null, "createtime" => time() ]); if ($parent_wallet) { $mWalletModel->where("id", $parent_wallet->id)->setInc("profit_amount", $real_name_check_pass); } } } $this->success("审核成功!"); // $valid = TencentCloudService::tencent_cloud_sms_send(TencentCloudService::$MASSAGE_APPLY, $massager["mobile"], [$is_pass ? "通过!" : "拒绝!"]); // if ($valid->code()) { // $this->success("审核成功!"); // } // $this->error($valid->msg()); } public function wallet($id = null) { if (!$id) $this->error("ID 为空!"); $m = $this->model->get($id); if (!$m) $this->error("助教不存在!"); $wallet = (new \app\api\model\massager\Wallet())->getWallet($id); $bill = (new \app\api\model\massager\Bill())->where("massager_id", $id)->limit(0, 100)->order("id", "desc")->select(); $this->assign("wallet", $wallet); $this->assign("rows", $bill); return $this->view->fetch(); } public function duration($ids = null, $page = 1) { $params = $this->request->param(); $starttime = strtotime(date("Y-m-01 00:00:00")); $endtime = strtotime(date("Y-m-d 23:59:59")); if (isset($params["startdate"])) { $s_strtotime = strtotime($params["startdate"]); if ($s_strtotime > 0) $starttime = $s_strtotime; } if (isset($params["enddate"])) { $e_strtotime = strtotime($params["enddate"]); if ($e_strtotime > 0) $endtime = strtotime(date("Y-m-d 23:59:59", $e_strtotime)); } $sumDuration = (new \app\admin\model\massager\Work()) ->where("massager_id", $ids) ->where("clock_in_time", ">=", $starttime) ->where("clock_off_time", "<=", $endtime) ->sum("duration"); $paginate = (new \app\admin\model\massager\Work()) ->where("massager_id", $ids) ->where("clock_in_time", ">=", $starttime) ->where("clock_off_time", "<=", $endtime) ->order("createtime", "desc") ->page($page) ->paginate( 10, false, [ "query" => [ "startdate" => isset($params["startdate"]) ? $params["startdate"] : null, "enddate" => isset($params["enddate"]) ? $params["enddate"] : null, ] ]); $this->view->assign([ "paginate" => $paginate, "startdate" => date("Y-m-d", $starttime), "enddate" => date("Y-m-d", $endtime), "sumDuration" => fixed2Float($sumDuration), ]); return $this->view->fetch(); } public function interiorScore($ids = null) { $params = $this->request->param(); $year = isset($params["year"]) ? $params["year"] : date("Y"); $month = isset($params["month"]) ? $params["month"] : date("m"); $interiorScoreDetails = (new MassagerService())->updateInteriorScore($ids, $year, $month); $this->view->assign([ "year" => $year, "month" => $month, "interiorScoreDetails" => $interiorScoreDetails, ]); return $this->view->fetch(); } public function chatlist($ids = null) { $res = \db("fastchat_session") ->where( "((user_id = '{$ids}||massager') OR (session_type = 6 AND session_user_id = {$ids}))" )->order("id", "desc") ->limit(100) ->select(); $result = []; foreach ($res as $item) { $user_id = null; if ($item["user_id"] == "{$ids}||massager") { $user_id = $item["session_user_id"]; } else { $user_id = explode("||", $item["user_id"])[0]; } $user = \db("user")->where("id", $user_id)->find(); if ($user) { array_push($result, [ "id" => $item["id"], "user" => $user, "massager_id" => $ids, "createtime" => $item["createtime"] ]); } } $this->view->assign("rows", $result); return $this->view->fetch(); } public function chatrecord() { $params = $this->request->param(); $start = strtotime('-7 days'); $end = time(); $records = \db("fastchat_record") ->where("session_id", $params["session_id"]) ->whereBetween('createtime', [$start, $end]) ->order("createtime", "ASC") ->select(); foreach ($records as &$record) { $record["class"] = strpos($record['sender'], "massager") ? "me" : "you"; } $this->view->assign("rows", $records); return $this->view->fetch(); } }