onlineUserId = $onlineUserId; $this->onlineEnterpriseId = $onlineEnterpriseId; $this->objDCashierPushMoneyDetail = new DCashierPushMoneyDetail(); $this->objDCashierPushMoneyDetail->setTable('qianniao_cashier_push_money_detail_'.$this->onlineEnterpriseId); $this->objDCashierConnectLog = new DCashierConnectLog(); $this->objDCashierConnectLog->setTable('qianniao_cashier_connect_log_'.$this->onlineEnterpriseId); $this->objDStaff = new DStaff(); $this->objDStaff->setTable('qianniao_staff_'.$this->onlineEnterpriseId); $this->objDUserBindEnterprise = new DUserBindEnterprise(); $this->objDUserCenter = new DUserCenter(); } /** * Doc: (des="提成明细") * User: XMing * Date: 2020/8/31 * Time: 5:42 下午 * @param array $selectParams * @return ResultWrapper */ public function getAll(array $selectParams) { $fields = '*'; $sql = 'SELECT '.$fields.' FROM qianniao_cashier_push_money_detail_'.$this->onlineEnterpriseId.' WHERE deleteStatus = '. StatusCode::$standard; if (isset($selectParams['pushType']) && !empty($selectParams['pushType'])){ $sql .= ' AND pushType = '.$selectParams['pushType']; } if (isset($selectParams['userCenterId']) && !empty($selectParams['userCenterId'])){ $sql .= ' AND userCenterId = '.$selectParams['userCenterId']; } if (isset($selectParams['startTime']) && !empty($selectParams['startTime']) && isset($selectParams['endTime']) && !empty($selectParams['endTime'])){ $sql .= ' AND createTime BETWEEN '.$selectParams['startTime'].' AND '.$selectParams['endTime']; } $count = count((array)$this->objDCashierPushMoneyDetail->query($sql)); $list = $this->objDCashierPushMoneyDetail->query($sql); if ($list === false){ return ResultWrapper::fail($this->objDCashierPushMoneyDetail->error(),ErrorCode::$dberror); } $ret = [ 'total' => $count, 'data' => $list ]; return ResultWrapper::success($ret); } /** * Doc: (des="交班记录列表") * User: XMing * Date: 2020/9/1 * Time: 11:14 上午 * @param array $selectParams * @return ResultWrapper */ public function getRecordList(array $selectParams) { $fields = '*'; $sql = 'SELECT '.$fields.' FROM qianniao_cashier_connect_log_'.$this->onlineEnterpriseId.' WHERE id IS NOT NULL'; if (isset($selectParams['isSelf']) && $selectParams['isSelf'] == StatusCode::$standard){ $sql .= ' AND userCenterId = '.$this->onlineUserId; }else{ //筛选 if (isset($selectParams['userCenterId']) && !empty($selectParams['userCenterId'])){ $sql .= ' AND userCenterId = '.$selectParams['userCenterId']; } } if (isset($selectParams['startTime']) && !empty($selectParams['startTime']) && isset($selectParams['endTime']) && !empty($selectParams['endTime'])){ $sql .= ' AND offDutyTime BETWEEN '.$selectParams['startTime'].' AND '.$selectParams['endTime']; } $count = count((array)$this->objDCashierConnectLog->query($sql)); if (isset($selectParams['limit'])){ $sql .= ' LIMIT '.$selectParams['offset'].','.$selectParams['limit']; } $list = $this->objDCashierConnectLog->query($sql); if ($list === false){ return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror); } $ret = [ 'total' => $count, 'data' => $list ]; return ResultWrapper::success($ret); } /** * Doc: (des="交接记录详情") * User: XMing * Date: 2020/9/1 * Time: 11:38 上午 * @param int $id * @return ResultWrapper */ public function getRecordInfo(int $id) { $result = $this->objDCashierConnectLog->get(['id'=>$id]); if ($result === false){ return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror); } $formatResult = self::formatListLog($result); if (!$formatResult->isSuccess()){ return ResultWrapper::fail($formatResult->getData(),$formatResult->getErrorCode()); } return ResultWrapper::success($formatResult->getData()); } /** * Doc: (des="") * User: XMing * Date: 2020/9/1 * Time: 12:11 下午 * @param array $data * @return ResultWrapper */ private function formatListLog(array $data) { if (empty($data)){ return ResultWrapper::success($data); } $data['collectionData'] = empty($data['collectionData']) ? [] : json_decode($data['collectionData'],true); $data['rechargeData'] = empty($data['rechargeData']) ? [] : json_decode($data['rechargeData'],true); $data['refundData'] = empty($data['refundData']) ? [] : json_decode($data['refundData'],true); return ResultWrapper::success($data); } /** * Doc: (des="1.获取当前登陆用户的交接详情") * User: XMing * Date: 2020/9/1 * Time: 12:03 下午 * @param int $shopId * @return ResultWrapper */ public function connectDetails(int $shopId) { $info = $this->objDCashierConnectLog->get(['workStatus'=>StatusCode::$auditStatus['auditIng'],'shopId' => $shopId,'userCenterId'=>$this->onlineUserId]); if ($info === false){ return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror); } if (empty($info)){ return ResultWrapper::fail('未获取到交接信息',ErrorCode::$paramError); } if ($info['workStatus'] != StatusCode::$auditStatus['auditIng']){ return ResultWrapper::fail('交接状态异常',ErrorCode::$paramError); } $formatResult = self::formatListLog($info); if (!$formatResult->isSuccess()){ return ResultWrapper::fail($formatResult->getData(),$formatResult->getErrorCode()); } return ResultWrapper::success($formatResult->getData()); } /** * Doc: (des="2.确定交接") * User: XMing * Date: 2020/9/1 * Time: 12:21 下午 * @param int $id * @param int $offDutyTime * @param string $remark * @return ResultWrapper */ public function confirmConnect(int $id,$offDutyTime,string $remark = '') { $info = $this->objDCashierConnectLog->get(['id' => $id]); if ($info === false){ return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror); } if (empty($info)){ return ResultWrapper::fail('未获取到交接信息',ErrorCode::$paramError); } if ($info['userCenterId'] != $this->onlineUserId){ return ResultWrapper::fail('交接信息有误',ErrorCode::$paramError); } if ($info['workStatus'] != StatusCode::$auditStatus['auditIng']){ return ResultWrapper::fail('交接状态异常',ErrorCode::$paramError); } //计算工作时长,修改工作状态 $hours = self::get_last_time($offDutyTime - $info['atWorkTime']); /**$jsonData = json_encode([ 'other' => '0.00', 'alipay' => '0.00', 'balance' => '0.00', 'cash' => '0.00', 'wechat' => '0.00' ]);*/ $update = [ 'updateTime' => time(), 'workStatus' => StatusCode::$auditStatus['auditPass'], 'remark' => $remark, 'offDutyTime' => $offDutyTime, 'hours' => $hours, // 'collectionMoney' => '0.00', // 'collectionData' => $jsonData, // 'rechargeMoney' => '0.00', // 'rechargeData' => $jsonData, // 'refundMoney' => '0.00', // 'refundData' => $jsonData ]; $updateResult = $this->objDCashierConnectLog->update($update,['id'=>$id]); if ($updateResult === false){ return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror); } return ResultWrapper::success('交接成功'); } /** * Doc: (des="收银登陆") * User: XMing * Date: 2020/9/1 * Time: 2:44 下午 * @param array $params * @return ResultWrapper */ public function loggerConnect(array $params) { $info = $this->objDCashierConnectLog->get(['userCenterId' => $this->onlineUserId,'shopId'=>$params['shopId'],'workStatus' => StatusCode::$auditStatus['auditIng']]); if ($info === false){ return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror); } if (!empty($info)){ return ResultWrapper::success(['msg' =>'上次登陆未交接,上次登陆时间: '.date('Y-m-d H:i:s',$info['atWorkTime']),'atWorkTime' => $info['atWorkTime'],'cashierUid'=>$info['userCenterId']]); } //由于超级管理员账号在staff中没有信息,所以先查询超管的账号 $userBindEnterprise = $this->objDUserBindEnterprise->get(['userCenterId'=>$this->onlineUserId,'enterpriseId'=>$this->onlineEnterpriseId,'roleType'=>1]); if ($userBindEnterprise === false){ return ResultWrapper::fail($this->objDUserBindEnterprise->error(),ErrorCode::$dberror); } if (!empty($userBindEnterprise)){ //获取手机号 $userCenter = $this->objDUserCenter->get(['id' => $this->onlineUserId],'mobile'); if ($userCenter === false){ return ResultWrapper::fail($this->objDUserCenter->error(),ErrorCode::$dberror); } if (empty($userCenter)){ return ResultWrapper::fail('未获取到用户信息',ErrorCode::$paramError); } //企业创建者 $staffInfo = [ 'staffName' => '超级管理员', 'mobile' => $userCenter['mobile'], 'staffId' => 0 ]; }else{ $fields = 's.id as staffId,s.mobile,s.staffName,s.userCenterId,d.signId'; $sql = 'SELECT '.$fields.' FROM qianniao_staff_'.$this->onlineEnterpriseId.' as s LEFT JOIN qianniao_department_role_'.$this->onlineEnterpriseId.' as d ON d.id = s.roleId WHERE s.userCenterId = '.$this->onlineUserId.' AND d.signId = '.StatusCode::$roleId['cashier']; $staffInfo = $this->objDStaff->query($sql); if ($staffInfo === false){ return ResultWrapper::fail($this->objDStaff->error(),ErrorCode::$dberror); } if (empty($staffInfo)){ return ResultWrapper::fail('未获取到收银员信息,或不是收银员',ErrorCode::$paramError); } $staffInfo = array_shift($staffInfo); } $time = time(); $jsonData = json_encode([ 'other' => '0.00', 'alipay' => '0.00', 'balance' => '0.00', 'cash' => '0.00', 'wechat' => '0.00' ]); $insert = [ 'staffName' => $staffInfo['staffName'], 'mobile' => $staffInfo['mobile'], 'atWorkTime' => $time, 'shopId' => $params['shopId'], 'createTime' => $time, 'workStatus' => StatusCode::$auditStatus['auditIng'], 'userCenterId' => $this->onlineUserId, 'collectionMoney' => '0.00', 'collectionData' => $jsonData, 'rechargeMoney' => '0.00', 'rechargeData' => $jsonData, 'refundMoney' => '0.00', 'refundData' => $jsonData ]; $insertResult = $this->objDCashierConnectLog->insert($insert); if ($insertResult === false){ return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror); } return ResultWrapper::success(['atWorkTime' => $time,'cashierUid' => $this->onlineUserId]); } /** * Doc: (des="") * User: XMing * Date: 2020/9/1 * Time: 2:12 下午 * @param int $time * @return string */ private static function get_last_time(int $time){ if ($time <= 60){ return $time.'秒'; } $d = floor($time / (3600*24)); $h = floor(($time % (3600*24)) / 3600); $m = floor((($time % (3600*24)) % 3600) / 60); if($d>'0'){ return $d.'天'.$h.'小时'.$m.'分'; }else{ if($h!='0'){ return $h.'小时'.$m.'分'; }else{ return $m.'分'; } } } }