RecruitmentRecord.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Facades\Servers\WechatMini\Mini;
  3. use App\Models\RecruitmentRecord as Model;
  4. use App\Models\Custom;
  5. use App\Models\RecruitmentActive;
  6. use function PHPUnit\Framework\isNull;
  7. /**
  8. * 拉新活动
  9. *
  10. * @author 刘相欣
  11. *
  12. */
  13. class RecruitmentRecord extends Auth{
  14. protected function _initialize(){
  15. parent::_initialize();
  16. $this->assign('breadcrumb1','拉新活动');
  17. $this->assign('breadcrumb2','活动数据列表');
  18. }
  19. /**
  20. * 列表页
  21. *
  22. * */
  23. public function index(Model $Model,Custom $Custom,RecruitmentActive $RecruitmentActive){
  24. // 接收参数
  25. $code = request('code','');
  26. $old_uid_code = request('old_uid_code','');
  27. $new_uid_code = request('new_uid_code','');
  28. $start_time = request('start_time','');
  29. $end_time = request('end_time','');
  30. // 查询条件
  31. $map = [];
  32. // 组合条件
  33. if( $code ) {
  34. $activeId = $RecruitmentActive->codeToId($code);
  35. $map[] = ['active_id','=',$activeId];
  36. }
  37. if( $old_uid_code ) {
  38. $old_uid = $Custom->codeToId($old_uid_code);
  39. $map[] = ['old_uid','=',$old_uid];
  40. }
  41. if( $new_uid_code ) {
  42. $new_uid = $Custom->codeToId($new_uid_code);
  43. $map[] = ['new_uid','=',$new_uid];
  44. }
  45. if( $start_time ) {
  46. $start_time = strtotime($start_time);
  47. $map[] = ['insert_time','>=',$start_time];
  48. }
  49. if( $end_time ) {
  50. $end_time = strtotime($end_time);
  51. $map[] = ['insert_time','<=',$end_time];
  52. }
  53. // 查询数据
  54. $list = $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
  55. // 循环处理数据
  56. foreach ($list as $key => $value) {
  57. if( $value['old_uid'] ) {
  58. $oldCustom = $Custom->getOne($value['old_uid']);
  59. if ($oldCustom){
  60. $value['old_name'] = $oldCustom['username'];
  61. $value['old_uid_code'] = $Custom->idToCode($oldCustom['uid']);
  62. }
  63. }
  64. if( $value['new_uid'] ) {
  65. $oldCustom = $Custom->getOne($value['new_uid']);
  66. if ($oldCustom){
  67. $value['new_name'] = $oldCustom['username'];
  68. $value['new_uid_code'] = $Custom->idToCode($oldCustom['uid']);
  69. }
  70. }
  71. if ($value['active_id']){
  72. $value['active_id_code'] = $RecruitmentActive->idToCode($value['active_id']);
  73. $value['active_name'] = $RecruitmentActive::query()->where('id','=',$value['active_id'])->value('name');
  74. }
  75. // 重组
  76. $list[$key] = $value;
  77. }
  78. // 分配数据
  79. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  80. $this->assign('list',$list);
  81. // 加载模板
  82. return $this->fetch();
  83. }
  84. }