MCashierPushMoneyDetail.Class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <?php
  2. namespace JinDouYun\Model\Cashier;
  3. use JinDouYun\Dao\Cashier\DCashierConnectLog;
  4. use JinDouYun\Dao\Cashier\DCashierPushMoneyDetail;
  5. use JinDouYun\Dao\Department\DStaff;
  6. use JinDouYun\Dao\Enterprise\DUserBindEnterprise;
  7. use JinDouYun\Dao\UserCenter\DUserCenter;
  8. use Mall\Framework\Core\ErrorCode;
  9. use Mall\Framework\Core\ResultWrapper;
  10. use Mall\Framework\Core\StatusCode;
  11. /**
  12. * Description:
  13. * Class MCashierPushMoneyDetail
  14. * @package JinDouYun\Model\Cashier
  15. */
  16. class MCashierPushMoneyDetail
  17. {
  18. /**
  19. * @var integer
  20. */
  21. private $onlineUserId;
  22. /**
  23. * @var integer
  24. */
  25. private $onlineEnterpriseId;
  26. /**
  27. * @var DCashierPushMoneyDetail
  28. */
  29. private $objDCashierPushMoneyDetail;
  30. /**
  31. * @var DCashierConnectLog
  32. */
  33. private $objDCashierConnectLog;
  34. /**
  35. * @var DStaff
  36. */
  37. private $objDStaff;
  38. /**
  39. * @var DUserBindEnterprise
  40. */
  41. private $objDUserBindEnterprise;
  42. /**
  43. * @var DUserCenter
  44. */
  45. private $objDUserCenter;
  46. /**
  47. * MCashierPushMoneyDetail constructor.
  48. * @param $onlineUserId
  49. * @param $onlineEnterpriseId
  50. * @throws \Exception
  51. */
  52. public function __construct($onlineUserId, $onlineEnterpriseId)
  53. {
  54. $this->onlineUserId = $onlineUserId;
  55. $this->onlineEnterpriseId = $onlineEnterpriseId;
  56. $this->objDCashierPushMoneyDetail = new DCashierPushMoneyDetail();
  57. $this->objDCashierPushMoneyDetail->setTable('qianniao_cashier_push_money_detail_'.$this->onlineEnterpriseId);
  58. $this->objDCashierConnectLog = new DCashierConnectLog();
  59. $this->objDCashierConnectLog->setTable('qianniao_cashier_connect_log_'.$this->onlineEnterpriseId);
  60. $this->objDStaff = new DStaff();
  61. $this->objDStaff->setTable('qianniao_staff_'.$this->onlineEnterpriseId);
  62. $this->objDUserBindEnterprise = new DUserBindEnterprise();
  63. $this->objDUserCenter = new DUserCenter();
  64. }
  65. /**
  66. * Doc: (des="提成明细")
  67. * User: XMing
  68. * Date: 2020/8/31
  69. * Time: 5:42 下午
  70. * @param array $selectParams
  71. * @return ResultWrapper
  72. */
  73. public function getAll(array $selectParams)
  74. {
  75. $fields = '*';
  76. $sql = 'SELECT '.$fields.' FROM qianniao_cashier_push_money_detail_'.$this->onlineEnterpriseId.'
  77. WHERE deleteStatus = '. StatusCode::$standard;
  78. if (isset($selectParams['pushType']) && !empty($selectParams['pushType'])){
  79. $sql .= ' AND pushType = '.$selectParams['pushType'];
  80. }
  81. if (isset($selectParams['userCenterId']) && !empty($selectParams['userCenterId'])){
  82. $sql .= ' AND userCenterId = '.$selectParams['userCenterId'];
  83. }
  84. if (isset($selectParams['startTime']) && !empty($selectParams['startTime']) && isset($selectParams['endTime']) && !empty($selectParams['endTime'])){
  85. $sql .= ' AND createTime BETWEEN '.$selectParams['startTime'].' AND '.$selectParams['endTime'];
  86. }
  87. $count = count((array)$this->objDCashierPushMoneyDetail->query($sql));
  88. $list = $this->objDCashierPushMoneyDetail->query($sql);
  89. if ($list === false){
  90. return ResultWrapper::fail($this->objDCashierPushMoneyDetail->error(),ErrorCode::$dberror);
  91. }
  92. $ret = [
  93. 'total' => $count,
  94. 'data' => $list
  95. ];
  96. return ResultWrapper::success($ret);
  97. }
  98. /**
  99. * Doc: (des="交班记录列表")
  100. * User: XMing
  101. * Date: 2020/9/1
  102. * Time: 11:14 上午
  103. * @param array $selectParams
  104. * @return ResultWrapper
  105. */
  106. public function getRecordList(array $selectParams)
  107. {
  108. $fields = '*';
  109. $sql = 'SELECT '.$fields.' FROM qianniao_cashier_connect_log_'.$this->onlineEnterpriseId.'
  110. WHERE id IS NOT NULL';
  111. if (isset($selectParams['isSelf']) && $selectParams['isSelf'] == StatusCode::$standard){
  112. $sql .= ' AND userCenterId = '.$this->onlineUserId;
  113. }else{
  114. //筛选
  115. if (isset($selectParams['userCenterId']) && !empty($selectParams['userCenterId'])){
  116. $sql .= ' AND userCenterId = '.$selectParams['userCenterId'];
  117. }
  118. }
  119. if (isset($selectParams['startTime']) && !empty($selectParams['startTime']) && isset($selectParams['endTime']) && !empty($selectParams['endTime'])){
  120. $sql .= ' AND offDutyTime BETWEEN '.$selectParams['startTime'].' AND '.$selectParams['endTime'];
  121. }
  122. $count = count((array)$this->objDCashierConnectLog->query($sql));
  123. if (isset($selectParams['limit'])){
  124. $sql .= ' LIMIT '.$selectParams['offset'].','.$selectParams['limit'];
  125. }
  126. $list = $this->objDCashierConnectLog->query($sql);
  127. if ($list === false){
  128. return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror);
  129. }
  130. $ret = [
  131. 'total' => $count,
  132. 'data' => $list
  133. ];
  134. return ResultWrapper::success($ret);
  135. }
  136. /**
  137. * Doc: (des="交接记录详情")
  138. * User: XMing
  139. * Date: 2020/9/1
  140. * Time: 11:38 上午
  141. * @param int $id
  142. * @return ResultWrapper
  143. */
  144. public function getRecordInfo(int $id)
  145. {
  146. $result = $this->objDCashierConnectLog->get(['id'=>$id]);
  147. if ($result === false){
  148. return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror);
  149. }
  150. $formatResult = self::formatListLog($result);
  151. if (!$formatResult->isSuccess()){
  152. return ResultWrapper::fail($formatResult->getData(),$formatResult->getErrorCode());
  153. }
  154. return ResultWrapper::success($formatResult->getData());
  155. }
  156. /**
  157. * Doc: (des="")
  158. * User: XMing
  159. * Date: 2020/9/1
  160. * Time: 12:11 下午
  161. * @param array $data
  162. * @return ResultWrapper
  163. */
  164. private function formatListLog(array $data)
  165. {
  166. if (empty($data)){
  167. return ResultWrapper::success($data);
  168. }
  169. $data['collectionData'] = empty($data['collectionData']) ? [] : json_decode($data['collectionData'],true);
  170. $data['rechargeData'] = empty($data['rechargeData']) ? [] : json_decode($data['rechargeData'],true);
  171. $data['refundData'] = empty($data['refundData']) ? [] : json_decode($data['refundData'],true);
  172. return ResultWrapper::success($data);
  173. }
  174. /**
  175. * Doc: (des="1.获取当前登陆用户的交接详情")
  176. * User: XMing
  177. * Date: 2020/9/1
  178. * Time: 12:03 下午
  179. * @param int $shopId
  180. * @return ResultWrapper
  181. */
  182. public function connectDetails(int $shopId)
  183. {
  184. $info = $this->objDCashierConnectLog->get(['workStatus'=>StatusCode::$auditStatus['auditIng'],'shopId' => $shopId,'userCenterId'=>$this->onlineUserId]);
  185. if ($info === false){
  186. return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror);
  187. }
  188. if (empty($info)){
  189. return ResultWrapper::fail('未获取到交接信息',ErrorCode::$paramError);
  190. }
  191. if ($info['workStatus'] != StatusCode::$auditStatus['auditIng']){
  192. return ResultWrapper::fail('交接状态异常',ErrorCode::$paramError);
  193. }
  194. $formatResult = self::formatListLog($info);
  195. if (!$formatResult->isSuccess()){
  196. return ResultWrapper::fail($formatResult->getData(),$formatResult->getErrorCode());
  197. }
  198. return ResultWrapper::success($formatResult->getData());
  199. }
  200. /**
  201. * Doc: (des="2.确定交接")
  202. * User: XMing
  203. * Date: 2020/9/1
  204. * Time: 12:21 下午
  205. * @param int $id
  206. * @param int $offDutyTime
  207. * @param string $remark
  208. * @return ResultWrapper
  209. */
  210. public function confirmConnect(int $id,$offDutyTime,string $remark = '')
  211. {
  212. $info = $this->objDCashierConnectLog->get(['id' => $id]);
  213. if ($info === false){
  214. return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror);
  215. }
  216. if (empty($info)){
  217. return ResultWrapper::fail('未获取到交接信息',ErrorCode::$paramError);
  218. }
  219. if ($info['userCenterId'] != $this->onlineUserId){
  220. return ResultWrapper::fail('交接信息有误',ErrorCode::$paramError);
  221. }
  222. if ($info['workStatus'] != StatusCode::$auditStatus['auditIng']){
  223. return ResultWrapper::fail('交接状态异常',ErrorCode::$paramError);
  224. }
  225. //计算工作时长,修改工作状态
  226. $hours = self::get_last_time($offDutyTime - $info['atWorkTime']);
  227. /**$jsonData = json_encode([
  228. 'other' => '0.00',
  229. 'alipay' => '0.00',
  230. 'balance' => '0.00',
  231. 'cash' => '0.00',
  232. 'wechat' => '0.00'
  233. ]);*/
  234. $update = [
  235. 'updateTime' => time(),
  236. 'workStatus' => StatusCode::$auditStatus['auditPass'],
  237. 'remark' => $remark,
  238. 'offDutyTime' => $offDutyTime,
  239. 'hours' => $hours,
  240. // 'collectionMoney' => '0.00',
  241. // 'collectionData' => $jsonData,
  242. // 'rechargeMoney' => '0.00',
  243. // 'rechargeData' => $jsonData,
  244. // 'refundMoney' => '0.00',
  245. // 'refundData' => $jsonData
  246. ];
  247. $updateResult = $this->objDCashierConnectLog->update($update,['id'=>$id]);
  248. if ($updateResult === false){
  249. return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror);
  250. }
  251. return ResultWrapper::success('交接成功');
  252. }
  253. /**
  254. * Doc: (des="收银登陆")
  255. * User: XMing
  256. * Date: 2020/9/1
  257. * Time: 2:44 下午
  258. * @param array $params
  259. * @return ResultWrapper
  260. */
  261. public function loggerConnect(array $params)
  262. {
  263. $info = $this->objDCashierConnectLog->get(['userCenterId' => $this->onlineUserId,'shopId'=>$params['shopId'],'workStatus' => StatusCode::$auditStatus['auditIng']]);
  264. if ($info === false){
  265. return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror);
  266. }
  267. if (!empty($info)){
  268. return ResultWrapper::success(['msg' =>'上次登陆未交接,上次登陆时间: '.date('Y-m-d H:i:s',$info['atWorkTime']),'atWorkTime' => $info['atWorkTime'],'cashierUid'=>$info['userCenterId']]);
  269. }
  270. //由于超级管理员账号在staff中没有信息,所以先查询超管的账号
  271. $userBindEnterprise = $this->objDUserBindEnterprise->get(['userCenterId'=>$this->onlineUserId,'enterpriseId'=>$this->onlineEnterpriseId,'roleType'=>1]);
  272. if ($userBindEnterprise === false){
  273. return ResultWrapper::fail($this->objDUserBindEnterprise->error(),ErrorCode::$dberror);
  274. }
  275. if (!empty($userBindEnterprise)){
  276. //获取手机号
  277. $userCenter = $this->objDUserCenter->get(['id' => $this->onlineUserId],'mobile');
  278. if ($userCenter === false){
  279. return ResultWrapper::fail($this->objDUserCenter->error(),ErrorCode::$dberror);
  280. }
  281. if (empty($userCenter)){
  282. return ResultWrapper::fail('未获取到用户信息',ErrorCode::$paramError);
  283. }
  284. //企业创建者
  285. $staffInfo = [
  286. 'staffName' => '超级管理员',
  287. 'mobile' => $userCenter['mobile'],
  288. 'staffId' => 0
  289. ];
  290. }else{
  291. $fields = 's.id as staffId,s.mobile,s.staffName,s.userCenterId,d.signId';
  292. $sql = 'SELECT '.$fields.' FROM qianniao_staff_'.$this->onlineEnterpriseId.' as s
  293. LEFT JOIN qianniao_department_role_'.$this->onlineEnterpriseId.' as d
  294. ON d.id = s.roleId WHERE s.userCenterId = '.$this->onlineUserId.' AND
  295. d.signId = '.StatusCode::$roleId['cashier'];
  296. $staffInfo = $this->objDStaff->query($sql);
  297. if ($staffInfo === false){
  298. return ResultWrapper::fail($this->objDStaff->error(),ErrorCode::$dberror);
  299. }
  300. if (empty($staffInfo)){
  301. return ResultWrapper::fail('未获取到收银员信息,或不是收银员',ErrorCode::$paramError);
  302. }
  303. $staffInfo = array_shift($staffInfo);
  304. }
  305. $time = time();
  306. $jsonData = json_encode([
  307. 'other' => '0.00',
  308. 'alipay' => '0.00',
  309. 'balance' => '0.00',
  310. 'cash' => '0.00',
  311. 'wechat' => '0.00'
  312. ]);
  313. $insert = [
  314. 'staffName' => $staffInfo['staffName'],
  315. 'mobile' => $staffInfo['mobile'],
  316. 'atWorkTime' => $time,
  317. 'shopId' => $params['shopId'],
  318. 'createTime' => $time,
  319. 'workStatus' => StatusCode::$auditStatus['auditIng'],
  320. 'userCenterId' => $this->onlineUserId,
  321. 'collectionMoney' => '0.00',
  322. 'collectionData' => $jsonData,
  323. 'rechargeMoney' => '0.00',
  324. 'rechargeData' => $jsonData,
  325. 'refundMoney' => '0.00',
  326. 'refundData' => $jsonData
  327. ];
  328. $insertResult = $this->objDCashierConnectLog->insert($insert);
  329. if ($insertResult === false){
  330. return ResultWrapper::fail($this->objDCashierConnectLog->error(),ErrorCode::$dberror);
  331. }
  332. return ResultWrapper::success(['atWorkTime' => $time,'cashierUid' => $this->onlineUserId]);
  333. }
  334. /**
  335. * Doc: (des="")
  336. * User: XMing
  337. * Date: 2020/9/1
  338. * Time: 2:12 下午
  339. * @param int $time
  340. * @return string
  341. */
  342. private static function get_last_time(int $time){
  343. if ($time <= 60){
  344. return $time.'秒';
  345. }
  346. $d = floor($time / (3600*24));
  347. $h = floor(($time % (3600*24)) / 3600);
  348. $m = floor((($time % (3600*24)) % 3600) / 60);
  349. if($d>'0'){
  350. return $d.'天'.$h.'小时'.$m.'分';
  351. }else{
  352. if($h!='0'){
  353. return $h.'小时'.$m.'分';
  354. }else{
  355. return $m.'分';
  356. }
  357. }
  358. }
  359. }