123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- /**
- * Author: luzheng.liu
- * Time: 2020/12/16 23:06
- */
- namespace app\api\controller;
- use app\api\BaseController;
- use app\api\model\BrandModel;
- use app\api\model\GroupModel;
- use app\api\model\StaffModel;
- use app\common\until\Until;
- class Staff extends BaseController {
- /**
- * @OA\Post(path="/api/Staff/index",
- * tags={"职员管理"},
- * summary="职员列表",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="ineger",default="1")),
- * @OA\Parameter(name="pageSize", in="query", description="页尺寸", @OA\Schema(type="integer",default="10")),
- * @OA\Parameter(name="status", in="query", description="状态 1正常 2删除", @OA\Schema(type="integer",default="1")),
- * @OA\Parameter(name="name", in="query", description="职员名", @OA\Schema(type="string")),
- * @OA\Parameter(name="mobile", in="query", description="手机号", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function index() {
- $input = request()->get();
- $model = new StaffModel();
- $model->setPage($input['page'] ?? 1);
- $model->setPageSize($input['pageSize'] ?? 10);
- if ($this->isAdmin()) {
- $where = [];
- } else {
- $where[] = ['s.status', '=', $model::NORMAL];
- }
- if (!empty($input['name'])) {
- $where[] = ['s.staff_name', 'like', "%{$input['name']}%"];
- }
- if (!empty($input['mobile'])) {
- $where[] = ['s.mobile', 'like', "%{$input['mobile']}%"];
- }
- $model->setWhere($where);
- $data = $model->getStaffList();
- Until::output($data);
- }
- /**
- * @OA\Post(path="/api/Staff/save",
- * tags={"职员管理"},
- * summary="保存职员信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\RequestBody(
- * @OA\MediaType(
- * mediaType="multipart/form-data",
- * @OA\Schema(
- * @OA\Property(description="职员名称", property="name", type="string", default="tony"),
- * @OA\Property(description="职员工号", property="code", type="string", default="A9527"),
- * @OA\Property(description="职员手机号", property="mobile", type="string", default="12367897654"),
- * @OA\Property(description="入职日期", property="joinTime", type="string", default="2020-01-04"),
- * @OA\Property(description="职称id", property="staffTitleId", type="integer", default="1"),
- * @OA\Property(description="storeId", property="storeId", type="integer", default="1"),
- * required={"name","code","mobile","joinTime","staffTitleId","storeId"})
- * )
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function save() {
- $input = Until::getInput();
- $rule = [
- 'name|职员名称' => 'require',
- 'code|职员工号' => 'require',
- 'mobile|职员手机号' => 'require',
- 'joinTime|入职日期' => 'require',
- 'staffTitleId|职称id' => 'require',
- 'storeId|storeId' => 'require',
- ];
- Until::check($rule, $input);
- $model = new StaffModel();
- if (!empty($input['id'])) {
- $id = (int)$input['id'];
- $model::where(['id' => $id])->update([
- 'staff_name' => $input['name'],
- 'staff_code' => $input['code'],
- 'mobile' => $input['mobile'],
- 'join_time' => $input['joinTime'],
- 'staff_title_id' => $input['staffTitleId'],
- 'store_id' => $input['storeId'],
- 'status' => $input['status'] ?? $model::NORMAL
- ]);
- } else {
- $id = $model->insertGetId([
- 'staff_name' => $input['name'],
- 'staff_code' => $input['code'],
- 'mobile' => $input['mobile'],
- 'join_time' => $input['joinTime'],
- 'staff_title_id' => $input['staffTitleId'],
- 'store_id' => $input['storeId']
- ]);
- }
- $where[] = ['s.id', '=', (int)$id];
- $model->setWhere($where);
- $info = $model->getStaffInfo();
- Until::output(['info' => $info]);
- }
- /**
- * @OA\GET(path="/api/Staff/read",
- * tags={"职员管理"},
- * summary="查看职员信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(name="id", in="query", description="职员id", @OA\Schema(type="ineger",default="1")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function read($id) {
- $model = new StaffModel();
- $where[] = ['s.id', '=', (int)$id];
- $model->setWhere($where);
- $info = $model->getStaffInfo();
- Until::output(['info' => $info]);
- }
- /**
- * @OA\GET(path="/api/Staff/delete",
- * tags={"职员管理"},
- * summary="删除职员信息",
- * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")),
- * @OA\Parameter(name="id", in="query", description="职员id", @OA\Schema(type="ineger",default="1")),
- * @OA\Parameter(name="status", in="query", description="1正常 2删除", @OA\Schema(type="ineger",default="1")),
- * @OA\RequestBody(
- * ),
- * @OA\Response(response="200", description="请求成功")
- * )
- */
- public function delete($id,$status) {
- $model = new StaffModel();
- $where[] = ['id', '=', (int)$id];
- $data = ['status' => (int)$status];
- $isSuccess = $model::where($where)->update($data);
- Until::output(['isSuccess' => $isSuccess]);
- }
- }
|