obj = new MCustomerCard($this->onlineEnterpriseId, $this->onlineUserId); $this->objShopCache = new ShopCache(); $this->objTempSaveCache = new TempSaveCache(); } /** * 添加和编辑商铺管理公共字段处理方法 * * @return array */ public function commonFieldFilter(){ $params = $this->request->getRawJson(); if( empty($params) ){ $this->sendOutput('参数为空', ErrorCode::$paramError ); } $shopData = [ 'uid' => isset($params['uid']) ? $params['uid'] : '', 'customer_id' => isset($params['customer_id']) ? $params['customer_id'] : '', 'project' => isset($params['project']) ? $params['project'] : '', 'time' => isset($params['time']) ? $params['time'] : '', ]; //非暂存则验空 if (!isset($params['tempSave']) || $params['tempSave'] == false) { foreach($shopData as $key => $value){ if(empty($value) && $value !== 0){ $this->sendOutput($key.'参数错误', ErrorCode::$paramError ); } } } $shopData['remarks']= isset($params['remarks']) ? $params['remarks'] : false; $shopData['pay_price']= isset($params['pay_price']) ? $params['pay_price'] : false; $shopData['to_price']= isset($params['to_price']) ? $params['to_price'] : false; $shopData['discount_price']= isset($params['discount_price']) ? $params['discount_price'] : false; return $shopData; } public function add() { $addStaffData = $this->commonFieldFilter(); $project = $this->Mproject->select([['id', 'in', $addStaffData['project']]]); $addStaffData['shop_id'] = $this->shopId; $price = 0; $service_time = 0; foreach ($project as $item) { $price += $item['price']; $service_time += $item['service_time']; } if ($addStaffData['to_price']){ $to_price = $addStaffData['to_price']; }else{ $to_price = $price; } if ($addStaffData['pay_price']) { $pay_price = $addStaffData['pay_price']; }else{ $pay_price = $price - $addStaffData['discount_price']; } $addStaffData['pay_price'] = $pay_price; $addStaffData['to_price'] = $to_price; $addStaffData['service_time'] = $service_time; $addStaffData['duration'] = $service_time; $result = $this->obj->insert($addStaffData); if ($result){ parent::sendOutput('添加成功'); }else{ parent::sendOutput($result->getData(), ErrorCode::$dberror); } } /** * 修改2 * @return void */ public function update() { $id = $this->request->param('id'); $param['project'] = $this->request->param('project'); $param['discount_price'] = $this->request->param('discount_price'); $param['to_price'] = $this->request->param('to_price'); $param['pay_price'] = $this->request->param('pay_price'); $param['time'] = $this->request->param('time'); $param['remarks'] = $this->request->param('remarks'); $data = $this->obj->details(['id' => $id]); if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode()); $param['time'] = strtotime($param['time']); $res = $this->obj->update($param, $id); if ($res->isSuccess()) { parent::sendOutput('修改成功'); } else { parent::sendOutput($res->getData(), $res->getErrorCode()); } } /** * 列表 */ public function list() { $params = $this->request->getRawJson(); $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $selectParams['shop_id'] = $this->shopId; //昵称 if(isset($params['nickname']) && !empty($params['nickname'])){ $selectParams['nickname'] = $params['nickname']; } //uid if(isset($params['uid']) && !empty($params['uid'])){ $selectParams['uid'] = $params['uid']; } if(isset($params['customer_id']) && !empty($params['customer_id'])){ $selectParams['customer_id'] = $params['customer_id']; } // 时间 if(isset($params['start_time']) && !empty($params['start_time']) and isset($params['end_time']) && !empty($params['end_time'])){ $response = []; $dt_start = strtotime($params['start_time']); $dt_end = strtotime($params['end_time']); while ($dt_start <= $dt_end) { array_push($response, date('Y-m-d', $dt_start)); $dt_start = strtotime('+1 day', $dt_start); } $selectParams['time'] = $response; } $result = $this->obj->list($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0,$pageData); } else { parent::sendOutput($result->getData(), ErrorCode::$dberror); } } public function complete() { $params = $this->request->getRawJson(); if (!$params['id']) $this->sendOutput('参数为空', ErrorCode::$paramError); $data = $this->obj->details(['id' => $params['id']]); if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode()); $data = $data->getData(); if ($data['status'] == 1) parent::sendOutput('订单已完成', 1005); $reward = 0; foreach ($data['project'] as $item){ $reward += $item['price'] * ($item['commission']/100); } $this->staff->service($reward, $data['uid'], $this->shopId, $data['id']); $res = $this->obj->update(['status'=> 1, 'paid' => 1], $params['id']); if ($res->isSuccess()) { parent::sendOutput('修改成功'); } else { parent::sendOutput($res->getData(), $res->getErrorCode()); } } /** * 取消预约订单 * @return void */ public function cancel() { $params = $this->request->getRawJson(); if (!$params['id']) $this->sendOutput('参数为空', ErrorCode::$paramError); $data = $this->obj->details(['id' => $params['id']]); if (!$data->isSuccess()) parent::sendOutput('订单不存在', $data->getErrorCode()); $data = $data->getData(); if ($data['status'] == 1) parent::sendOutput('订单已完成', 1005); $res = $this->obj->update(['status'=> -1], $params['id']); if ($res->isSuccess()) { parent::sendOutput('取消成功'); } else { parent::sendOutput($res->getData(), $res->getErrorCode()); } } /** * 详情 * @return void */ public function details() { $params = $this->request->getRawJson(); $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; if(!empty($params['id'])){ $selectParams['id'] = $params['id']; } $result = $this->obj->details($selectParams); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } public function delete() { $id['id'] = $this->request->param('id'); if (empty($id['id'])) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $result = $this->obj->delete($id); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } }