Regiment.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php namespace App\Http\Controllers\Admin;
  2. use App\Models\Regiment as Model;
  3. use App\Models\Product as Product;
  4. use App\Models\RegimentActive as RegimentActive;
  5. use App\Models\Custom as Custom;
  6. use Illuminate\Support\Facades\DB;
  7. /**
  8. * 团列表
  9. *
  10. * @author jun
  11. *
  12. */
  13. class Regiment 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,Product $Product,RegimentActive $RegimentActive,Custom $Custom){
  24. // 接收参数
  25. $name = request('name','');
  26. // 查询条件
  27. $map = [];
  28. // 组合条件
  29. if( $name ) $map[] = ['regiment.name','=',$name];
  30. $select = [
  31. 'regiment.*',
  32. 'regiment_active.name as active_name',
  33. 'product.name as product_name',
  34. 'custom.username as username',
  35. ];
  36. // 查询数据
  37. $list = $Model->query()
  38. ->join('regiment_active','regiment_active.id','=','regiment.active_id')
  39. ->join('product','product.id','=','regiment.product_id')
  40. ->leftJoin('custom','custom.uid','=','regiment.custom_uid')
  41. ->where($map)
  42. ->select($select)
  43. ->orderByDesc('id')
  44. ->paginate(config('page_num',10));
  45. // 循环处理数据
  46. foreach($list as &$v){
  47. $v['product_code'] = $Product->idToCode($v['product_id']);
  48. $v['active_code'] = $RegimentActive->idToCode($v['active_id']);
  49. if ($v['custom_uid']){
  50. $v['custom_code'] = $Custom->idToCode($v['custom_uid']);
  51. }
  52. }
  53. // 分配数据
  54. $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
  55. $this->assign('list',$list);
  56. // 加载模板
  57. return $this->fetch();
  58. }
  59. }