| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- <?php
- namespace app\admin\controller\users;
- use app\api\model\taxi\MotorRecord;
- use app\common\controller\AdminController;
- use app\common\model\Seller;
- use app\common\model\TaxiOrder;
- use app\http\IResponse;
- use think\App;
- use think\Exception;
- use think\Request;
- use think\Validate;
- class MotorAgent extends AdminController
- {
- protected $model;
- public function __construct(App $app = null)
- {
- parent::__construct($app);
- $this->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([],'操作成功');
- }
- }
|