| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace hd\controllers;
- use bizHd\custom\classes\CustomClass;
- use bizHd\custom\classes\HdClass;
- use bizHd\deduct\classes\DeductClass;
- use common\components\util;
- use Yii;
- class DeductController extends BaseController
- {
- public $guestAccess = [];
- //减少余额 ssh 20250329(这个方法应该建在CustomController的)
- public function actionDeductAmount()
- {
- $post = Yii::$app->request->post();
- $customId = $post['customId'] ?? 0;
- $remark = $post['remark'] ?? '';
- $custom = CustomClass::getByID($customId, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- if ($custom->shopId != $this->shopId) {
- util::fail('不是你的客户');
- }
- $hdId = $custom->hdId;
- $hd = HdClass::getByID($hdId, true);
- if (empty($hd)) {
- util::fail('客户信息缺失,编号7756');
- }
- $amount = $post['amount'] ?? 0;
- if (empty($amount)) {
- util::fail('请填写金额');
- }
- if ($amount < 0) {
- util::fail('金额要大于0');
- }
- $staff = $this->shopAdmin;
- if ($staff->finance == 0) {
- util::fail('没有财务权限');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $shop = $this->shop;
- $staffId = $staff->id;
- $staffName = $staff->name;
- $params = [
- 'remark' => $remark,
- 'staffId' => $staffId,
- 'staffName' => $staffName,
- ];
- DeductClass::doDeduct($shop, $custom, $hd, $amount, $params);
- $transaction->commit();
- util::complete('减少成功');
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info("减少报错:" . $exception->getMessage());
- util::fail('减少失败');
- }
- }
- }
|