1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php namespace App\Http\Controllers\Admin;
- use App\Models\Regiment as Model;
- use App\Models\Product as Product;
- use App\Models\RegimentActive as RegimentActive;
- use App\Models\Custom as Custom;
- use Illuminate\Support\Facades\DB;
- /**
- * 团列表
- *
- * @author jun
- *
- */
- class Regiment extends Auth{
- protected function _initialize(){
- parent::_initialize();
- $this->assign('breadcrumb1','拼团活动');
- $this->assign('breadcrumb2','团列表');
- }
- /**
- * 列表页
- *
- * */
- public function index(Model $Model,Product $Product,RegimentActive $RegimentActive,Custom $Custom){
- // 接收参数
- $name = request('name','');
- // 查询条件
- $map = [];
- // 组合条件
- if( $name ) $map[] = ['regiment.name','=',$name];
- $select = [
- 'regiment.*',
- 'regiment_active.name as active_name',
- 'product.name as product_name',
- 'custom.username as username',
- ];
- // 查询数据
- $list = $Model->query()
- ->join('regiment_active','regiment_active.id','=','regiment.active_id')
- ->join('product','product.id','=','regiment.product_id')
- ->leftJoin('custom','custom.uid','=','regiment.custom_uid')
- ->where($map)
- ->select($select)
- ->orderByDesc('id')
- ->paginate(config('page_num',10));
- // 循环处理数据
- foreach($list as &$v){
- $v['product_code'] = $Product->idToCode($v['product_id']);
- $v['active_code'] = $RegimentActive->idToCode($v['active_id']);
- if ($v['custom_uid']){
- $v['custom_code'] = $Custom->idToCode($v['custom_uid']);
- }
- }
- // 分配数据
- $this->assign('empty', '<tr><td colspan="20">~~暂无数据</td></tr>');
- $this->assign('list',$list);
- // 加载模板
- return $this->fetch();
- }
- }
|