123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 |
- <?php
- namespace JinDouYun\Model\Cashier;
- use JinDouYun\Dao\Cashier\DCashierConnectLog;
- use JinDouYun\Dao\Cashier\DCashierPushMoneyDetail;
- use JinDouYun\Dao\Department\DStaff;
- use JinDouYun\Dao\Enterprise\DUserBindEnterprise;
- use JinDouYun\Dao\UserCenter\DUserCenter;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- /**
- * Description:
- * Class MCashierPushMoneyDetail
- * @package JinDouYun\Model\Cashier
- */
- class MCashierPushMoneyDetail
- {
- /**
- * @var integer
- */
- private $onlineUserId;
- /**
- * @var integer
- */
- private $onlineEnterpriseId;
- /**
- * @var DCashierPushMoneyDetail
- */
- private $objDCashierPushMoneyDetail;
- /**
- * @var DCashierConnectLog
- */
- private $objDCashierConnectLog;
- /**
- * @var DStaff
- */
- private $objDStaff;
- /**
- * @var DUserBindEnterprise
- */
- private $objDUserBindEnterprise;
- /**
- * @var DUserCenter
- */
- private $objDUserCenter;
- /**
- * MCashierPushMoneyDetail constructor.
- * @param $onlineUserId
- * @param $onlineEnterpriseId
- * @throws \Exception
- */
- public function __construct($onlineUserId, $onlineEnterpriseId)
- {
- $this->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.'分';
- }
- }
- }
- }
|