MotorAgent.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\model\users;
  3. use app\common\model\GoodsOrder;
  4. use app\common\model\MissionOrder;
  5. use app\common\model\SkillOrder;
  6. use app\common\model\TaxiOrder;
  7. use app\http\IResponse;
  8. use think\Model;
  9. class MotorAgent extends Model
  10. {
  11. protected $name = 'users_motor_agent';
  12. protected $append = [
  13. 'status_text'
  14. ];
  15. public function getStatusTextAttr($value, $data)
  16. {
  17. if (isset($data['status']) && $data) {
  18. $status = [10=>'待审核',20=>'已拒绝',30=>'已通过',40=>'已缴费',50=>'已锁定'];
  19. return $status[$data['status']];
  20. }
  21. return '待审核';
  22. }
  23. public function user(): \think\model\relation\HasOne
  24. {
  25. return $this->hasOne('\app\common\model\Users', 'id', 'user_id')
  26. ->field('id,nickname,partnership');
  27. }
  28. public function stats()
  29. {
  30. $user = $this->where('status', '>', 20)
  31. ->select();
  32. $agent_num = count($user);
  33. $total_num = 0;
  34. $total_amount = 0;
  35. if ($user) {
  36. $area_ids = [];
  37. foreach ($user as $item) {
  38. $area_ids[] = $item->area_id;
  39. }
  40. $TaxiOrder = new TaxiOrder();
  41. $taxi_order = $TaxiOrder->whereIn('area_id', $area_ids)->whereNotIn('status', [1])->column('price', 'id');
  42. $total_num += count($taxi_order);
  43. $total_amount += array_sum($taxi_order);
  44. }
  45. return [
  46. 'agent_num' => $agent_num,
  47. 'total_num' => $total_num,
  48. 'total_amount' => $total_amount,
  49. ];
  50. }
  51. }