request->get(); $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today'; $startTime = $get['startTime'] ?? ''; $endTime = $get['endTime'] ?? ''; $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true); $start = $period['startTime']; $end = $period['endTime']; $currentStartDate = date('Y-m-d', strtotime($start)); $currentEndDate = date('Y-m-d', strtotime($end)); $currentStartTime = $currentStartDate . ' 00:00:00'; $currentEndTime = $currentEndDate . ' 23:59:59'; $where = ['mainId' => $this->mainId]; $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]]; $where['delStatus'] = 0; //过滤掉已删除的 $list = ExpendClass::getAllByCondition($where, null, '*', null); $arr = []; $cat = []; $map = dict::getDict('expendTypeMap'); foreach ($map as $id => $name) { $cat[$id] = ['num' => 0, 'amount' => 0, 'name' => $name]; } $totalExpend = 0; if (!empty($list)) { foreach ($list as $expend) { $staffId = $expend['staffId'] ?? 0; $amount = $expend['amount'] ?? 0; $staffName = $expend['staffName'] ?? ''; $bx = $expend['bx'] ?? 0; $type = $expend['type'] ?? 0; $currentAmount = $amount; if ($bx == 0) { $hasAmount = 0; $unAmount = $amount; } else { $hasAmount = $amount; $unAmount = 0; } if (isset($arr[$staffId])) { //总支出 $arr[$staffId]['totalAmount'] = floatval(bcadd($arr[$staffId]['totalAmount'], $currentAmount)); //已报销 $arr[$staffId]['hasAmount'] = floatval(bcadd($arr[$staffId]['hasAmount'], $hasAmount)); //待报销 $arr[$staffId]['amount'] = floatval(bcadd($arr[$staffId]['amount'], $unAmount)); $arr[$staffId]['num'] = bcadd($arr[$staffId]['num'], 1); } else { $arr[$staffId]['totalAmount'] = floatval($currentAmount); $arr[$staffId]['hasAmount'] = floatval($hasAmount); $arr[$staffId]['amount'] = floatval($unAmount); $arr[$staffId]['staffName'] = $staffName; $arr[$staffId]['num'] = 1; } $totalExpend = bcadd($totalExpend, $currentAmount, 2); if (isset($cat[$type])) { $cat[$type]['num']++; $cat[$type]['amount'] = floatval(bcadd($cat[$type]['amount'], $amount, 2)); } } } util::success(['list' => $arr, 'totalExpend' => $totalExpend, 'catList' => $cat]); } //报销汇总统计 ssh 20240308 public function actionUnBxList() { ini_set('memory_limit', '2045M'); set_time_limit(0); $where = ['mainId' => $this->mainId, 'bx' => 0, 'delStatus' => 0]; $list = ExpendClass::getAllByCondition($where, null, '*', null); $arr = []; if (!empty($list)) { foreach ($list as $expend) { $staffId = $expend['staffId'] ?? 0; $amount = $expend['amount'] ?? 0; $staffName = $expend['staffName'] ?? ''; $currentAmount = $amount; $unAmount = $amount; if (isset($arr[$staffId])) { $arr[$staffId]['amount'] = bcadd($arr[$staffId]['amount'], $unAmount, 2); $arr[$staffId]['num'] = bcadd($arr[$staffId]['num'], 1); } else { $arr[$staffId]['totalAmount'] = $currentAmount; $arr[$staffId]['amount'] = $unAmount; $arr[$staffId]['staffName'] = $staffName; $arr[$staffId]['num'] = 1; } } } util::success(['list' => $arr]); } //报销金额 ssh 20240308 public function actionBx() { $staff = $this->shopAdmin; if (isset($staff->finance) == false || $staff->finance == 0) { util::fail('请财务操作'); } $mainId = $this->mainId; if (getenv('YII_ENV') == 'production') { if (in_array($mainId, [23390])) { if (!in_array($this->adminId, [24655])) { util::fail('请财务人员操作'); } } } else { if (in_array($mainId, [644])) { if (!in_array($this->adminId, [919])) { //util::fail('请财务人员操作哈'); } } } $get = Yii::$app->request->get(); $postAmount = $get['amount'] ?? 0; $staffId = $get['staffId'] ?? 0; if ($postAmount <= 0) { util::fail('没有需要报销的金额'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $condition = ['mainId' => $this->mainId, 'bx' => 0, 'staffId' => $staffId, 'delStatus' => 0]; $list = ExpendClass::getAllByCondition($condition, null, '*', null, true); $total = 0; $staff = $this->shopAdmin; $bxData = [ 'mainId' => $this->mainId, 'staffId' => $staff->id ?? 0, 'staffName' => $staff->name ?? '', ]; $bx = ExpendBxClass::add($bxData, true); $bxId = $bx->id ?? 0; foreach ($list as $it) { $amount = $it->amount ?? 0; $total = bcadd($total, $amount, 2); $it->bx = 1; $it->bxId = $bxId; $it->save(); } $bx->amount = $total; $bx->save(); if (floatval($postAmount) != floatval($total)) { util::fail('金额错误,请刷新页面,实际:' . floatval($total)); } $transaction->commit(); util::complete(); } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); noticeUtil::push("报销出错了,错误信息:{$msg}", '15280215347'); util::fail(); } } //类型列表 ssh 20240308 public function actionGetTypeList() { $list = dict::getDict('expendTypeList'); util::success(['list' => $list]); } public function actionList() { $get = Yii::$app->request->get(); $bx = $get['bx'] ?? -1; $type = $get['type'] ?? -1; $staffId = $get['staffId'] ?? 0; $where = []; $where['mainId'] = $this->mainId; if (!empty($staffId)) { $where['staffId'] = $staffId; } if ($type != -1) { $where['type'] = $type; } if ($bx != -1) { $where['bx'] = $bx; } $where['delStatus'] = 0; $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'thisYear'; $startTime = $get['startTime'] ?? ''; $endTime = $get['endTime'] ?? ''; $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true); $start = $period['startTime']; $end = $period['endTime']; $currentStartDate = date('Y-m-d', strtotime($start)); $currentEndDate = date('Y-m-d', strtotime($end)); $currentStartTime = $currentStartDate . ' 00:00:00'; $currentEndTime = $currentEndDate . ' 23:59:59'; $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]]; $respond = ExpendClass::getExpendList($where); $map = dict::getDict('expendTypeMap'); if (!empty($respond['list'])) { foreach ($respond['list'] as $key => $val) { $type = $val['type'] ?? 0; $name = $map[$type] ?? '未命名'; $respond['list'][$key]['typeName'] = $name; } } util::success($respond); } //新增支出 ssh 20220710 public function actionAddExpend() { $mainId = $this->mainId; if (getenv('YII_ENV') == 'production') { if (in_array($mainId, [23390])) { if (!in_array($this->adminId, [24655])) { util::fail('请财务人员操作吧'); } } else { } } else { if (in_array($mainId, [644])) { if (!in_array($this->adminId, [919])) { //util::fail('请财务人员操作哦'); } } } //避免重复提交 util::checkRepeatCommit($this->adminId, 10); $post = Yii::$app->request->post(); $type = $post['type'] ?? -1; $amount = $post['amount'] ?? 0; $remark = $post['remark'] ?? ''; $bx = $post['bx'] ?? -1; if (!is_numeric($amount) || $amount <= 0) { util::fail('请输入正确的金额'); } if ($bx == -1) { util::fail('请选报销状态'); } if ($type == -1) { util::fail('请选择类型'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $payWay = $post['payWay'] ?? 0; if ($payWay == dict::getDict('payWay', 'cash')) { //扣除现金 $mainId = $this->mainId; $main = MainClass::getLockById($mainId); if (empty($main)) { util::fail('没有门店信息'); } $balance = bcsub($main->money, $amount, 2); if ($balance < 0) { util::fail('现金不足'); } $main->money = $balance; $main->save(); $staffId = $this->shopAdminId; $staff = $this->shopAdmin; $staffName = $staff->name ?? ''; $map = dict::getDict('expendTypeMap'); $expendName = $map[$type] ?? '未知'; $event = $staffName . $expendName . '支出' . $amount . '元'; $capitalType = dict::getDict('capitalType', 'expendRegister', 'id'); $data = []; $data['balance'] = $balance; $data['mainId'] = $mainId; $data['sjId'] = $this->sjId; $data['amount'] = $amount; $data['staffId'] = $staffId; $data['staffName'] = $staffName; $data['ptStyle'] = dict::getDict('ptStyle', 'ghs'); $data['capitalType'] = $capitalType; $data['event'] = $event; $data['remark'] = $remark; ShopMoneyClass::addData($data); } $remark = $post['remark'] ?? ''; $getStaffId = $post['getStaffId'] ?? 0; $staff = ShopAdminClass::getById($getStaffId, true); if (empty($staff)) { util::fail('没有找到员工'); } if ($staff->mainId != $this->mainId) { util::fail('没有员工'); } $staffName = $staff->name ?? ''; $ptStyle = dict::getDict('ptStyle', 'ghs'); $payTime = date("Y-m-d H:i:s"); $historyDate = $post['historyDate'] ?? ''; if (!empty($historyDate)) { $payTime = $historyDate . date(" H:i:s"); } $expendData = [ 'type' => $type, 'amount' => $amount, 'remark' => $remark, 'mainId' => $this->mainId, 'staffId' => $getStaffId, 'staffName' => $staffName, 'ptStyle' => $ptStyle, 'payWay' => $payWay, 'bx' => $bx, 'payTime' => $payTime, ]; $respond = ExpendClass::add($expendData, true); if ($bx == 1) { $bxData = [ 'mainId' => $this->mainId, 'staffId' => $getStaffId, 'staffName' => $staffName, 'remark' => '登记时已报销', ]; $bxInfo = ExpendBxClass::add($bxData, true); $bxId = $bxInfo->id ?? 0; $bxInfo->amount = $amount; $bxInfo->save(); $respond->bxId = $bxId; $respond->save(); } $transaction->commit(); util::complete(); } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); noticeUtil::push("登记支出失败,错误信息:{$msg}", '15280215347'); } } //删除支出 public function actionDelExpend() { $post = Yii::$app->request->post(); $staff = $this->shopAdmin; if ($staff->finance == 0) { util::fail('没有财务权限'); } $staffId = $this->shopAdminId; $id = intval($post['id']); $expend = ExpendClass::getById($id, true); if ($expend->mainId != $this->mainId) { util::fail('没有找到支出数据'); } if ($expend->delStatus == 1) { util::fail('此支出数据已是删除状态'); } // 处理报销表数据 if ($expend->bxId != 0) { $expendBx = ExpendBxClass::getById($expend->bxId, true); $expendBx->amount = bcsub($expendBx->amount, $expend->amount, 2); //怕remark字段不足,这边缩短长度 $expendBx->remark = $expendBx->remark . "|删除支出ID " . $expend->id; $expendBx->save(); } $expend->delStaffId = $staffId; $expend->delStaffName = $staff->name; $expend->delStatus = 1; $rs = $expend->save(); if ($rs) { util::complete(); } else { util::fail('删除支出失败'); } } //修改账单日期 ssh 20241122 public function actionChangePayTime() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $date = $get['date'] ?? ''; if (empty($date)) { util::fail('没有日期'); } $expend = ExpendClass::getById($id, true); if (empty($expend)) { util::fail('没有找到报销'); } if ($expend->mainId != $this->mainId) { util::fail('不是你的报销'); } $addTime = $expend->addTime; $expend->payTime = $date . date(" H:i:s", strtotime($addTime)); $expend->save(); util::complete('修改成功'); } }