|
@@ -18,8 +18,13 @@ class CanteenController extends Controller
|
|
|
}
|
|
}
|
|
|
$data['stall_imgs'] = Helper::formatImgsFiled($data['stall_imgs']);
|
|
$data['stall_imgs'] = Helper::formatImgsFiled($data['stall_imgs']);
|
|
|
$school = DB::getInfoById('school', $data['school_id'], 'name');
|
|
$school = DB::getInfoById('school', $data['school_id'], 'name');
|
|
|
- $company = DB::getInfoById('company', $data['company_id'], 'name');
|
|
|
|
|
- $data['company_name'] = $company['name']?? '';
|
|
|
|
|
|
|
+ $cri = DbCriteria::simpleCompare(['t.canteen_id' => $id])
|
|
|
|
|
+ ->setSelect('c.name,c.id')
|
|
|
|
|
+ ->setAlias('t')
|
|
|
|
|
+ ->setJoin('left join wx_company c on c.id=t.company_id');
|
|
|
|
|
+ $companyInfo = DB::getInfoWithCriteria('company_canteen_relation', $cri);
|
|
|
|
|
+ $data['company_name'] = $companyInfo['name']?? '';
|
|
|
|
|
+ $data['company_id'] = $companyInfo['id']?? '';
|
|
|
$data['school_name'] = $school['name']?? '';
|
|
$data['school_name'] = $school['name']?? '';
|
|
|
Helper::ok($data);
|
|
Helper::ok($data);
|
|
|
}
|
|
}
|
|
@@ -57,18 +62,28 @@ class CanteenController extends Controller
|
|
|
$data = DB::getListWithCriteria(self::$table, $cri);
|
|
$data = DB::getListWithCriteria(self::$table, $cri);
|
|
|
if (!empty($data['records'])) {
|
|
if (!empty($data['records'])) {
|
|
|
$users = Helper::arrayColumn(
|
|
$users = Helper::arrayColumn(
|
|
|
- DB::getListWithCriteria('useradmin', DbCriteria::simpleCompare([])->setSelect('id, username')),
|
|
|
|
|
|
|
+ DB::getListWithCriteria('useradmin', DbCriteria::simpleCompare(['id' => array_column($data['records'], 'last_user_id')])->setSelect('id, username')),
|
|
|
'username',
|
|
'username',
|
|
|
'id'
|
|
'id'
|
|
|
);
|
|
);
|
|
|
$schools = Helper::arrayColumn(
|
|
$schools = Helper::arrayColumn(
|
|
|
- DB::getListWithCriteria('school', DbCriteria::simpleCompare([])->setSelect('id, name')),
|
|
|
|
|
|
|
+ DB::getListWithCriteria('school', DbCriteria::simpleCompare(['id' => array_column($data['records'], 'school_id')])->setSelect('id, name')),
|
|
|
'name',
|
|
'name',
|
|
|
'id'
|
|
'id'
|
|
|
);
|
|
);
|
|
|
- $data['records'] = array_map(function ($item) use ($users, $schools) {
|
|
|
|
|
|
|
+ $cri = DbCriteria::simpleCompare([['t.canteen_id' => array_column($data['records'], 'id')]])
|
|
|
|
|
+ ->setSelect('c.name,t.canteen_id')
|
|
|
|
|
+ ->setAlias('t')
|
|
|
|
|
+ ->setJoin('left join wx_company c on c.id=t.company_id');
|
|
|
|
|
+ $relations = Helper::arrayColumn(
|
|
|
|
|
+ DB::getListWithCriteria('company_canteen_relation', $cri),
|
|
|
|
|
+ 'name',
|
|
|
|
|
+ 'canteen_id'
|
|
|
|
|
+ );
|
|
|
|
|
+ $data['records'] = array_map(function ($item) use ($users, $schools, $relations) {
|
|
|
$item['last_user_name'] = $users[$item['last_user_id']] ?? '-';
|
|
$item['last_user_name'] = $users[$item['last_user_id']] ?? '-';
|
|
|
$item['school_name'] = $schools[$item['school_id']] ?? '-';
|
|
$item['school_name'] = $schools[$item['school_id']] ?? '-';
|
|
|
|
|
+ $item['company_name'] = $relations[$item['id']] ?? '-';
|
|
|
$item['stall_imgs'] = Helper::formatImgsFiled($item['stall_imgs']);
|
|
$item['stall_imgs'] = Helper::formatImgsFiled($item['stall_imgs']);
|
|
|
return $item;
|
|
return $item;
|
|
|
}, $data['records']);
|
|
}, $data['records']);
|
|
@@ -123,7 +138,7 @@ class CanteenController extends Controller
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
$notNullField = ["school_id","name","stall_num","is_direct","username","phone","weixin"];
|
|
$notNullField = ["school_id","name","stall_num","is_direct","username","phone","weixin"];
|
|
|
- $allowEmptyField = ["school_id","stall_num","is_direct"];
|
|
|
|
|
|
|
+ $allowEmptyField = ["stall_num","is_direct"];
|
|
|
|
|
|
|
|
// 空字段检测
|
|
// 空字段检测
|
|
|
if (!Helper::checkEmptyKey($data, $notNullField, $allowEmptyField)) {
|
|
if (!Helper::checkEmptyKey($data, $notNullField, $allowEmptyField)) {
|
|
@@ -141,10 +156,19 @@ class CanteenController extends Controller
|
|
|
}
|
|
}
|
|
|
$data['stall_imgs'] = $data['stall_imgs'] ? implode(',', $data['stall_imgs']) : '';
|
|
$data['stall_imgs'] = $data['stall_imgs'] ? implode(',', $data['stall_imgs']) : '';
|
|
|
|
|
|
|
|
- if ($id) {
|
|
|
|
|
- DB::updateById(self::$table, $data, $id);
|
|
|
|
|
- } else {
|
|
|
|
|
- DB::addData(self::$table, $data);
|
|
|
|
|
|
|
+ $trans = \Yii::app()->db->beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ if ($id) {
|
|
|
|
|
+ DB::updateById(self::$table, $data, $id);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ DB::addData(self::$table, $data);
|
|
|
|
|
+ }
|
|
|
|
|
+ Db::deleteByCondition('company_canteen_relation', ['canteen_id' => $id]);
|
|
|
|
|
+ Db::addData('company_canteen_relation', ['canteen_id' => $id, 'company_id' => $data['school_id'], 'school_id' => $data['school_id']]);
|
|
|
|
|
+ $trans->commit();
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ $trans->rollback();
|
|
|
|
|
+ Helper::error($e->getMessage());
|
|
|
}
|
|
}
|
|
|
Helper::ok();
|
|
Helper::ok();
|
|
|
}
|
|
}
|