链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.6 KiB

5 years ago
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Admin\Common\Order;
  4. use App\Models\LanzuCsInfo;
  5. use App\Models\LanzuUserRelationBind;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\DB;
  8. use \App\Models\v3\CsInfo as modelCsInfo;
  9. class CsInfoStatis extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'command:CsInfoStatis';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = 'export CsInfoStatis';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return int
  36. */
  37. public function handle()
  38. {
  39. $rows = $this->getSaleMan();
  40. dd($rows);
  41. return 0;
  42. }
  43. /**
  44. * 获取拓展员
  45. */
  46. public function getSaleMan()
  47. {
  48. $data = LanzuCsInfo::select(
  49. DB::raw('count("lanzu_cs_info.person_id") as total'),
  50. DB::raw('group_concat(lanzu_cs_info.admin_user_id) as admin_user_id'),
  51. DB::raw('group_concat(rb.user_id) as user_id'),
  52. 'lanzu_cs_info.person_id','lanzu_user.nick_name')
  53. ->groupBy('lanzu_cs_info.person_id')
  54. ->leftJoin('lanzu_user','lanzu_user.id','lanzu_cs_info.person_id')
  55. ->leftJoin('lanzu_user_relation_bind as rb','rb.source_id','lanzu_cs_info.admin_user_id')
  56. ->where('lanzu_cs_info.person_id','>',0)->get()->toArray();
  57. foreach ($data as $key=>$value){
  58. $value['admin_user_id'] = array_unique(explode(',',$value['admin_user_id']));
  59. $row = $this->csDetail($value['admin_user_id'],-30);
  60. dump($row);
  61. }
  62. }
  63. /**
  64. * 获取站点详情
  65. */
  66. public function csDetail($adminUid,$option)
  67. {
  68. $data = modelCsInfo::whereIn('admin_user_id',$adminUid)
  69. ->paginate(10)
  70. ->toArray();
  71. foreach ($data['data'] as &$value){
  72. //>>1.获取绑定后下过单的用户
  73. $value['user_num'] = LanzuUserRelationBind::where('source_id',$value['admin_user_id'])->count();
  74. $uid = Order::getUserOrder($value['admin_user_id']);
  75. //>>2.获取订单数据
  76. $value['order_user_num'] = Order::getOrderData([
  77. 'user_type'=>'lanzu_biz',//谁取数据 user_type 用户类型
  78. 'data_type'=>'count_user',//取什么数据 data_type 数据类型
  79. 'market_id'=>'',//取哪个市场数据
  80. 'condition'=>1,//取数据维度 condition
  81. 'user_ids'=>$uid?$uid:null
  82. ],$option);//下单人数
  83. $value['order_num'] = Order::getOrderData([
  84. 'user_type'=>'lanzu_biz',//谁取数据 user_type 用户类型
  85. 'data_type'=>'number',//取什么数据 data_type 数据类型
  86. 'market_id'=>'',//取哪个市场数据
  87. 'condition'=>1,//取数据维度 condition
  88. 'user_ids'=>$uid?$uid:null
  89. ],$option);//订单数
  90. $value['order_amount'] = Order::getOrderData([
  91. 'user_type'=>'lanzu_biz',//谁取数据 user_type 用户类型
  92. 'data_type'=>'amount',//取什么数据 data_type 数据类型
  93. 'market_id'=>'',//取哪个市场数据
  94. 'condition'=>1,//取数据维度 condition
  95. 'user_ids'=>$uid?$uid:null
  96. ],$option);//订单金额
  97. }
  98. dd($data);
  99. }
  100. }