model = new \app\admin\model\users\MotorAgent(); } /** * 显示资源列表 * * @return \think\Response * @throws \think\exception\DbException */ public function index() { $params = input(); $params['card_id'] = input('card_id/s', ''); $params['nickname'] = input('nickname/s', ''); $where = []; if ($params['nickname']) { $where['nickname'] = ['like', '%' . $params['nickname'] . '%']; } $list = $this->model->with(['user']) ->where($where) ->order(['id' => 'desc']) ->paginate(input('limit', 10),false); return IResponse::paginate($list); } /** * @desc 统计数据 * @return mixed * @author weichuanbao<654745815@qq.com> * @date 2022/1/4 0004 */ public function stats() { return IResponse::success($this->model->stats()); } /** * 显示创建资源表单页. * * @param $ids * @return \think\Response * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function create($ids) { $row = $this->model::get($ids); if (!$row) { return IResponse::failure('记录不存在'); } $Seller = new Seller(); $TaxiOrder = new TaxiOrder(); // 商户数量 $seller = $Seller->where(['area_id' => $row['area_id']])->count(); // 订单数据 // 摩的订单,技能订单,商品订单,配送订单 $taxi_order = $TaxiOrder->whereIn('area_id', $row['area_id'])->whereNotIn('status', [1])->column('price', 'id'); $total_order = count($taxi_order); $turnover = array_sum($taxi_order); return IResponse::success([ 'region' => $row['area'], 'total_order' => $total_order, 'turnover' => $turnover, 'seller' => $seller, 'taxi_order' => $taxi_order, ]); } /** * 保存新建的资源 * * @param \think\Request $request * @return \think\Response */ public function save(Request $request) { // } /** * 显示指定的资源 * * @param int $id * @return \think\Response */ public function read($id) { // } /** * 显示编辑资源表单页. * * @param int $id * @return \think\Response */ public function edit($id) { // } /** * 保存更新的资源 * * @param int $id * @return \think\Response * @throws \think\exception\PDOException */ public function update($id) { $row = $this->model::get($id); if (!$row) { return IResponse::failure('记录不存在'); } $params = input(); $Validate = new Validate([ 'mobile' => 'require' ], [ 'mobile.require' => '手机号必须', ]); if (!$Validate->check($params)) { return IResponse::failure($Validate->getError()); } $result = false; $this->model->startTrans(); try { $result = $row->allowField(true)->save($params); $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); } if ($result) { return IResponse::success('成功'); } return IResponse::failure('失败'); } /** * @desc 审核 * @param $ids * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException * @author weichuanbao<654745815@qq.com> * @date 2021/12/22 0022 */ public function check($ids) { $row = $this->model::get($ids); if (!$row) { IResponse::failure('记录不存在'); } if ($row['status'] >= 30) { IResponse::failure('用户已经通过审核,无需操作'); } $user = model('\app\common\model\Users')->field('id,is_motor_agent')->find($row['user_id']); $result = false; $this->model->startTrans(); try { $user->is_motor_agent = 2; $user->save(); $row->status = 30; $row->save(); // 新建角色 $Role = new \app\agent\model\auth\Role(); // $PermissionRole = new \app\agent\model\auth\PermissionRole(); // 获取角色权限 // $permissionRole = $PermissionRole::get(2); $role = $Role::create([ 'name' => 'motor_agent_'.$row['user_id'], 'description' => '系统管理员', 'user_id' => $row['user_id'], ], true); // 创建摩的代理后台账号 $User = new \app\agent\model\auth\User(); $admin = $User::create([ 'username' => $row['account'], 'email' => $row['mobile'].'@rrj.com', 'password' => password_hash(input('password/s'), PASSWORD_BCRYPT), 'user_id' => $row['user_id'], 'area_id' => $row['area_id'], ], true); // 写入用户权限 $AgentCasbin = new \CasbinAdapter\Think\Facades\AgentCasbin(); $result = $AgentCasbin::AddRoleForUser('user_id_' . $admin['id'], $role['name']); // 赋予角色权限 $this->model->authority($role['id'], $role['name']); $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); IResponse::failure($e->getMessage()); } if ($result) { IResponse::success(); } IResponse::failure('失败'); } /** * @desc 删除 * @param $ids * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException * @author weichuanbao<654745815@qq.com> * @date 2021/12/22 0022 */ public function deluser($ids) { $row = $this->model::get($ids); if (!$row) { IResponse::failure('记录不存在'); } Db::table('ins_users_motor_agent')->where('$ids',1)->delete(); IResponse::success([],'操作成功'); } /** * @desc 发放合伙资产 * @param $ids * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException * @author weichuanbao<654745815@qq.com> * @date 2022/1/7 0007 */ public function partnership($ids) { $row = $this->model->with('user')->find($ids); if (!$row) { IResponse::failure('记录不存在'); } $params = input(); $params['amount'] = input('amount', 0); $MotorRecord = new MotorRecord(); $result = false; $this->model->startTrans(); try { $row->user->partnership = $params['amount']; $result = $row->user->save(); $MotorRecord->setMoneyLog($row['user'], 'partnership', $params['amount'], 30, '发放合伙资产'); $MotorRecord->saveMoneyLog(); $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); } if ($result) { IResponse::success([],'成功'); } IResponse::failure('失败'); } /** * 删除指定资源 * * @param int $id * @return \think\Response */ public function delete($id) { // $row = $this->model::get($ids); if (!$row) { IResponse::failure('记录不存在'); } Db::table('ins_users_motor_agent')->where('$ids',1)->delete(); IResponse::success([],'操作成功'); } }