链街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.

121 lines
4.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Admin\Actions\Excel;
  3. use App\Models\LanzuCsInfo;
  4. use Illuminate\Support\Facades\DB;
  5. use Maatwebsite\Excel\Concerns\FromArray;
  6. use Maatwebsite\Excel\Concerns\WithStrictNullComparison;
  7. use App\Admin\Common\Order;
  8. use App\Models\LanzuUserRelationBind;
  9. use \App\Models\v3\CsInfo as modelCsInfo;
  10. class SalesMan implements FromArray, WithStrictNullComparison
  11. {
  12. protected $_name;
  13. protected $_option;
  14. public function __construct($option,$name)
  15. {
  16. $this->_name = $name;
  17. $this->_option = $option;
  18. }
  19. public function array(): array
  20. {
  21. $result[] = [
  22. '懒ID',
  23. '拓展员',
  24. '服务站点',
  25. '站点地址',
  26. '绑定用户数',
  27. $this->_name.'下单人数',
  28. $this->_name.'订单数',
  29. $this->_name.'订单金额',
  30. ];
  31. $res = $this->getSaleMan(-30);
  32. foreach ($res as $value){
  33. $item =[];
  34. $item[] = $value['person_id'];
  35. $item[] = $value['real_name']??$value['nick_name'];
  36. $item[] = $value['name'];
  37. $item[] = $value['address'];
  38. $item[] = $value['user_num']??0;
  39. $item[] = $value['order_user_num']??0;
  40. $item[] = $value['order_num']??0;
  41. $item[] = $value['order_amount']??0;
  42. $result[] = $item;
  43. }
  44. return $result;
  45. }
  46. /**
  47. * 获取拓展员
  48. */
  49. public function getSaleMan($option)
  50. {
  51. $data = LanzuCsInfo::select(
  52. DB::raw('count("lanzu_cs_info.person_id") as total'),
  53. DB::raw('group_concat(lanzu_cs_info.admin_user_id) as admin_user_id'),
  54. DB::raw('group_concat(rb.user_id) as user_id'),
  55. 'lanzu_cs_info.person_id', 'lanzu_user.nick_name')
  56. ->groupBy('lanzu_cs_info.person_id')
  57. ->leftJoin('lanzu_user', 'lanzu_user.id', 'lanzu_cs_info.person_id')
  58. ->leftJoin('lanzu_user_relation_bind as rb', 'rb.source_id', 'lanzu_cs_info.admin_user_id')
  59. ->where('lanzu_cs_info.person_id', '>', 0)->get()->toArray();
  60. $result = [];
  61. foreach ($data as $key => $value) {
  62. $value['admin_user_id'] = array_unique(explode(',', $value['admin_user_id']));
  63. $result = $this->csDetail($value['admin_user_id'], $this->_option, $value['nick_name'], $result);
  64. }
  65. return $result;
  66. }
  67. /**
  68. * 获取站点详情
  69. */
  70. public function csDetail($adminUid, $option, $nickName, $result)
  71. {
  72. $data = modelCsInfo::whereIn('lanzu_cs_info.admin_user_id', $adminUid)
  73. ->select('lanzu_cs_info.*','lanzu_employees.name as real_name')
  74. ->leftJoin('lanzu_employees', function ($join){
  75. $join->on('lanzu_employees.user_id','=', 'lanzu_cs_info.person_id')
  76. ->where('lanzu_employees.status','=',1);
  77. })
  78. ->get()->toArray();
  79. list($beginTime,$endTime) = Order::beginAndEnd($option);
  80. foreach ($data as &$value) {
  81. //>>1.获取绑定后下过单的用户
  82. $value['user_num'] = LanzuUserRelationBind::where('source_id', $value['admin_user_id'])->whereBetween('created_at',[$beginTime,$endTime])->count();
  83. $uid = Order::getUserOrder($value['admin_user_id']);
  84. //>>2.获取订单数据
  85. $value['order_user_num'] = Order::getOrderData([
  86. 'user_type' => 'lanzu_biz',//谁取数据 user_type 用户类型
  87. 'data_type' => 'count_user',//取什么数据 data_type 数据类型
  88. 'market_id' => '',//取哪个市场数据
  89. 'condition' => 1,//取数据维度 condition
  90. 'user_ids' => $uid ? $uid : null
  91. ], $option);//下单人数
  92. $value['order_num'] = Order::getOrderData([
  93. 'user_type' => 'lanzu_biz',//谁取数据 user_type 用户类型
  94. 'data_type' => 'number',//取什么数据 data_type 数据类型
  95. 'market_id' => '',//取哪个市场数据
  96. 'condition' => 1,//取数据维度 condition
  97. 'user_ids' => $uid ? $uid : null
  98. ], $option);//订单数
  99. $value['order_amount'] = Order::getOrderData([
  100. 'user_type' => 'lanzu_biz',//谁取数据 user_type 用户类型
  101. 'data_type' => 'amount',//取什么数据 data_type 数据类型
  102. 'market_id' => '',//取哪个市场数据
  103. 'condition' => 1,//取数据维度 condition
  104. 'user_ids' => $uid ? $uid : null
  105. ], $option);//订单金额
  106. $value['nick_name'] = $nickName;
  107. $result[] = $value;
  108. }
  109. return $result;
  110. }
  111. }