| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace ghs\controllers;
- use bizGhs\expend\classes\ExpendClass;
- use bizGhs\shop\classes\MainClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use bizGhs\shop\classes\ShopMoneyClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\util;
- use Yii;
- class ExpendController extends BaseController
- {
- //待报销人员列表和金额 ssh 20240308
- public function actionUnBxList()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $list = ExpendClass::getAllByCondition(['mainId' => $this->mainId, 'bx' => 0], null, '*', null);
- $arr = [];
- if (!empty($list)) {
- foreach ($list as $expend) {
- $staffId = $expend['staffId'] ?? 0;
- $amount = $expend['amount'] ?? 0;
- $staffName = $expend['staffName'] ?? '';
- if (isset($arr[$staffId])) {
- $arr[$staffId]['amount'] = bcadd($arr[$staffId]['amount'], $amount);
- $arr[$staffId]['num'] = bcadd($arr[$staffId]['num'], 1);
- } else {
- $arr[$staffId]['amount'] = $amount;
- $arr[$staffId]['staffName'] = $staffName;
- $arr[$staffId]['num'] = 1;
- }
- }
- }
- util::success(['list' => $arr]);
- }
- //类型列表 ssh 20240308
- public function actionGetTypeList()
- {
- $list = dict::getDict('expendTypeMap');
- util::success(['list' => $list]);
- }
- public function actionList()
- {
- $where = [];
- $where['mainId'] = $this->mainId;
- $list = ExpendClass::getExpendList($where);
- util::success($list);
- }
- //新增支出 ssh 20220710
- public function actionAddExpend()
- {
- $post = Yii::$app->request->post();
- $type = $post['type'] ?? 0;
- $amount = $post['amount'] ?? 0;
- $remark = $post['remark'] ?? '';
- if (is_numeric($amount) == false || $amount <= 0) {
- 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'] ?? '';
- $staffName = $this->shopAdmin->name ?? '';
- $ptStyle = dict::getDict('ptStyle', 'ghs');
- $expendData = [
- 'type' => $type,
- 'amount' => $amount,
- 'remark' => $remark,
- 'mainId' => $this->mainId,
- 'staffId' => $this->shopAdminId,
- 'staffName' => $staffName,
- 'ptStyle' => $ptStyle,
- 'payWay' => $payWay,
- ];
- ExpendClass::add($expendData);
- $transaction->commit();
- util::complete();
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("登记支出失败,错误信息:{$msg}", '15280215347');
- }
- }
- }
|