|
|
@@ -3,7 +3,10 @@
|
|
|
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;
|
|
|
|
|
|
@@ -22,16 +25,70 @@ class ExpendController extends BaseController
|
|
|
public function actionAddExpend()
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
- $type = $post['type'] ?? dict::getDict('expendType', 'hs');
|
|
|
+ $type = $post['type'] ?? 0;
|
|
|
$amount = $post['amount'] ?? 0;
|
|
|
+ $remark = $post['remark'] ?? '';
|
|
|
if (is_numeric($amount) == false || $amount <= 0) {
|
|
|
util::fail('请输入正确的金额');
|
|
|
}
|
|
|
- $remark = $post['remark'] ?? '';
|
|
|
- $staffName = $this->shopAdmin->name ?? '';
|
|
|
- $data = ['type' => $type, 'amount' => $amount, 'remark' => $remark, 'mainId' => $this->mainId, 'staffId' => $this->shopAdminId, 'staffName' => $staffName];
|
|
|
- ExpendClass::add($data);
|
|
|
- util::complete();
|
|
|
+ $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('没有门店信息');
|
|
|
+ }
|
|
|
+ $hasMoney = $main->money ?? 0;
|
|
|
+ if ($amount > $hasMoney) {
|
|
|
+ util::fail('现金不足');
|
|
|
+ }
|
|
|
+
|
|
|
+ $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['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,
|
|
|
+ ];
|
|
|
+ ExpendClass::add($expendData);
|
|
|
+ $transaction->commit();
|
|
|
+ util::complete();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $transaction->rollBack();
|
|
|
+ $msg = $e->getMessage();
|
|
|
+ noticeUtil::push("登记支出失败,错误信息:{$msg}", '15280215347');
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|