| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\admin\model\users;
- use app\agent\model\auth\Access;
- use app\agent\model\auth\Permission;
- use app\agent\model\auth\PermissionRole;
- use app\agent\model\auth\Role;
- use app\common\model\TaxiOrder;
- use think\Model;
- class MotorAgent extends Model
- {
- protected $name = 'users_motor_agent';
- protected $append = [
- 'status_text'
- ];
- public function getStatusTextAttr($value, $data)
- {
- if (isset($data['status']) && $data) {
- $status = [10=>'待审核',20=>'已拒绝',30=>'已通过',40=>'已缴费',50=>'已锁定'];
- return $status[$data['status']];
- }
- return '待审核';
- }
- public function user(): \think\model\relation\HasOne
- {
- return $this->hasOne('\app\common\model\Users', 'id', 'user_id')
- ->field('id,nickname,partnership');
- }
- /**
- * @desc 摩的代理统计数据
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function stats()
- {
- $user = $this->where('status', '>', 20)
- ->select();
- $agent_num = count($user);
- $total_num = 0;
- $total_amount = 0;
- if ($user) {
- $area_ids = [];
- foreach ($user as $item) {
- $area_ids[] = $item->area_id;
- }
- $TaxiOrder = new TaxiOrder();
- $taxi_order = $TaxiOrder->whereIn('area_id', $area_ids)->whereNotIn('status', [1])->column('price', 'id');
- $total_num += count($taxi_order);
- $total_amount += array_sum($taxi_order);
- }
- return [
- 'agent_num' => $agent_num,
- 'total_num' => $total_num,
- 'total_amount' => $total_amount,
- ];
- }
- public function authority($RoleId, $roleName)
- {
- $Role = new Role();
- $Access = new Access();
- $Permission = new Permission();
- $PermissionRole = new PermissionRole();
- // 获取角色信息
- $role = $Role::get($RoleId);
- if ($role){
- $admin = $PermissionRole::where('role_id', 2)->find();
- $PermissionRole::create([
- 'role_id' => $RoleId,
- 'permission_idx' => $admin['permission_idx']
- ]);
- $access = $Access->where('v0', 'motor_agent_173')
- ->select();
- foreach ($access as $item) {
- $item->v0 = $roleName;
- $item->hidden = ['id'];
- }
- $Access->allowField(true)->saveAll($access->toArray());
- }
- }
- }
|