| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace ghs\controllers;
- use bizGhs\expend\classes\ExpendClass;
- use bizGhs\shop\classes\MainClass;
- use bizGhs\shop\classes\ShopMoneyClass;
- use common\components\dict;
- use common\components\noticeUtil;
- use common\components\util;
- use Yii;
- class ExpendController extends BaseController
- {
- 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');
- }
- }
- }
|