|
@@ -6,6 +6,8 @@ use App\Models\AdminUser;
|
|
|
use App\Models\City;
|
|
|
use App\Models\AuthRule;
|
|
|
use App\Models\AdminRule;
|
|
|
+use App\Models\Company;
|
|
|
+use App\Models\AdminHistory;
|
|
|
use Illuminate\Support\Carbon;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
@@ -38,27 +40,48 @@ class Business extends Auth{
|
|
|
// 查询条件
|
|
|
$map = [];
|
|
|
// 编码ID
|
|
|
- if( $id ) $map[] = ['id','=',$id];
|
|
|
- if( $phone ) $map[] = ['phone','=',$phone];
|
|
|
- if( $startTime ) $map[] = ['insert_time','>=',Carbon::createFromFormat('Y-m-d',$startTime)->startOfDay()->getTimestamp()];
|
|
|
- if( $startTime ) $map[] = ['insert_time','<=',Carbon::createFromFormat('Y-m-d',$startTime)->endOfDay()->getTimestamp()];
|
|
|
- if( !is_null($status) ) $map[] = ['status','=',$status];
|
|
|
+ if( $id ) $map[] = ['business.id','=',$id];
|
|
|
+ if( $phone ) $map[] = ['business.phone','=',$phone];
|
|
|
+ if( $startTime ) $map[] = ['business.insert_time','>=',Carbon::createFromFormat('Y-m-d',$startTime)->startOfDay()->getTimestamp()];
|
|
|
+ if( $startTime ) $map[] = ['business.insert_time','<=',Carbon::createFromFormat('Y-m-d',$startTime)->endOfDay()->getTimestamp()];
|
|
|
+ if( !is_null($status) ) $map[] = ['business.status','=',$status];
|
|
|
$session = session('userRule');
|
|
|
if ($session){
|
|
|
$map[] = ['company_id','=',$session['company_id']];
|
|
|
if ($session['business_id']){
|
|
|
- $map[] = ['id','=',$session['business_id']];
|
|
|
+ $map[] = ['business.id','=',$session['business_id']];
|
|
|
}
|
|
|
if ($session['menu_type'] == 1 && $session['data_type'] == 2){
|
|
|
- $map[] = ['leader_uid','=',$session['admin_uid']];
|
|
|
+ $map[] = ['business.leader_uid','=',$session['admin_uid']];
|
|
|
}
|
|
|
}
|
|
|
// 查询数据
|
|
|
- $list = $Model->query()->where($map)->orderByDesc('id')->paginate(config('page_num',10));
|
|
|
+ $list = $Model->query()
|
|
|
+ ->join('company','company.id','=','business.company_id')
|
|
|
+ ->join('admin','admin.uid','=','business.admin_uid')
|
|
|
+ ->where($map)
|
|
|
+ ->orderByDesc('business.id')
|
|
|
+ ->select('business.*','company.name as company_name', 'admin.username as username','admin.phone as admin_phone')
|
|
|
+ ->paginate(config('page_num',10));
|
|
|
// 循环处理数据
|
|
|
foreach ($list as $key => $value) {
|
|
|
// id转编号
|
|
|
$value['business_code'] = $Model->idToCode($value['id']);
|
|
|
+ $value['logopic'] = $value['logopic'] ? path_compat($value['logopic']) : '';
|
|
|
+ $addHistory = AdminHistory::query()
|
|
|
+ ->join('admin','admin.uid','=','admin_history.admin_uid')
|
|
|
+ ->where(['admin_history.primary_id'=>$value['id'],'admin_history.notes_type'=>1,'admin_history.table_name'=>$Model->getTable()])
|
|
|
+ ->select('admin_history.insert_time','admin.username as username')
|
|
|
+ ->first();
|
|
|
+ $editHistory = AdminHistory::query()
|
|
|
+ ->join('admin','admin.uid','=','admin_history.admin_uid')
|
|
|
+ ->where(['admin_history.primary_id'=>$value['id'],'admin_history.notes_type'=>2,'admin_history.table_name'=>$Model->getTable()])
|
|
|
+ ->select('admin_history.update_time','admin.username as username')
|
|
|
+ ->orderByDesc('id')->first();
|
|
|
+ $value['add_history_username'] = $addHistory ? $addHistory->username : '';
|
|
|
+ $value['add_history_time'] = $addHistory ? $addHistory->insert_time : 0;
|
|
|
+ $value['edit_history_username'] = $editHistory ? $editHistory->username : '';
|
|
|
+ $value['edit_history_time'] = $editHistory ? $editHistory->update_time : 0;
|
|
|
// 重组
|
|
|
$list[$key] = $value;
|
|
|
if( $value['city_ids'] ) {
|