obj = new MShopSubscribe($this->onlineEnterpriseId, $this->onlineUserId); $this->Mproject = new MShopProject($this->onlineEnterpriseId); $this->staff = new MStaff($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'] : '', // 'pay_price' => isset($params['pay_price']) ? $params['pay_price'] : '', // 'to_price' => isset($params['to_price']) ? $params['to_price'] : '', ]; //非暂存则验空 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['discount_price'] = isset($params['discount_price']) ? $params['discount_price'] : false; $shopData['shop_id'] = isset($params['shop_id']) ? $params['shop_id'] : false; return $shopData; } public function add() { $addStaffData = $this->commonFieldFilter(); $project = $this->Mproject->select([['id', 'in', $addStaffData['project']]]); if ($addStaffData['shop_id']) { $addStaffData['shop_id'] = $addStaffData['shop_id']; } else { $addStaffData['shop_id'] = $this->shopId; } $price = 0; $service_time = 0; $cost_price = 0; foreach ($project as $item) { $price += $item['price']; $cost_price += $item['cost_price']; $service_time += $item['service_time']; } // if ($addStaffData['to_price']) { // $to_price = $addStaffData['to_price']; // } else { // $to_price = $price; // } // $pay_price = $project['price']; $to_price = $item['price']; $pay_price = $price - $addStaffData['discount_price']; // if ($addStaffData['pay_price']) { // $pay_price = $addStaffData['pay_price']; // } else { // $pay_price = $price - $addStaffData['discount_price']; // } $addStaffData['order_id'] = 'wx'.$addStaffData['customer_id'].time().$this->getRandPass(8); $addStaffData['pay_price'] = $pay_price; $addStaffData['cost_price'] = $cost_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); } } public function getRandPass($length = 8) { $order_id = ''; $chars = "0123456789"; $char_len = strlen($chars); for ($i = 0; $i <= $length; $i++) { $loop = mt_rand(0, ($char_len - 1)); $order_id .= $chars[$loop]; } return $order_id; } /** * 修改2 * @return void */ public function update() { $id = $this->request->param('id'); $param['uid'] = $this->request->param('uid'); $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()); $project = $this->Mproject->select([['id', 'in', $param['project']]]); $cost_price = 0; foreach ($project as $item) { $cost_price += $item['cost_price']; } $param['cost_price'] = $cost_price; $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->params(); $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; if ($this->shopId) { $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['type']) && !empty($params['type'])) { $selectParams['type'] = $params['type']; } // 时间 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); $res = $this->obj->update(['status' => 1, 'paid' => 1, 'completeTime' => time(), 'pay_price' => $data['pay_price'] + $data['stay_price']], $params['id']); if ($res->isSuccess()) { $this->staff->stock($data['uid']); // 发放员工股份 $this->staff->recommend($data, $this->shopId); // 发放客户提成 $this->staff->service($data, $this->shopId); // 发放员工提成 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, 'completeTime' => time()], $params['id']); if ($res->isSuccess()) { parent::sendOutput('取消成功'); } else { parent::sendOutput($res->getData(), $res->getErrorCode()); } } /** * 取消预约订单 * @return void */ public function confirm_payment() { $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['paid'] == 1) parent::sendOutput('订单已支付', 1005); $res = $this->obj->update(['paid' => 1, 'completeTime' => time()], $params['id']); if ($res->isSuccess()) { parent::sendOutput('成功'); } else { parent::sendOutput($res->getData(), $res->getErrorCode()); } } /** * 详情 * @return void */ public function details() { $where = []; $id = $this->request->param('id'); if (!empty($id)) { $where['id'] = $id; } $result = $this->obj->details($where)->getData(); $project_id = explode(',', $result['project']); $result['project'] = []; foreach ($project_id as $vo) { $project = $this->Mproject->get(['id' => $vo], 'id,name,price,ot_price,info,image'); $result['project'][] = $project; } // $project = $this->Mproject->select([['id', 'in', $result['project']]], 'id,name,price,ot_price,info,image'); // $result['project'] = $project; parent::sendOutput($result); } 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()); } } }