DeductController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\custom\classes\CustomClass;
  4. use bizHd\custom\classes\HdClass;
  5. use bizHd\deduct\classes\DeductClass;
  6. use common\components\util;
  7. use Yii;
  8. class DeductController extends BaseController
  9. {
  10. public $guestAccess = [];
  11. //减少余额 ssh 20250329(这个方法应该建在CustomController的)
  12. public function actionDeductAmount()
  13. {
  14. $post = Yii::$app->request->post();
  15. $customId = $post['customId'] ?? 0;
  16. $remark = $post['remark'] ?? '';
  17. $custom = CustomClass::getByID($customId, true);
  18. if (empty($custom)) {
  19. util::fail('没有找到客户');
  20. }
  21. if ($custom->shopId != $this->shopId) {
  22. util::fail('不是你的客户');
  23. }
  24. $hdId = $custom->hdId;
  25. $hd = HdClass::getByID($hdId, true);
  26. if (empty($hd)) {
  27. util::fail('客户信息缺失,编号7756');
  28. }
  29. $amount = $post['amount'] ?? 0;
  30. if (empty($amount)) {
  31. util::fail('请填写金额');
  32. }
  33. if ($amount < 0) {
  34. util::fail('金额要大于0');
  35. }
  36. $staff = $this->shopAdmin;
  37. if($staff->finance == 0){
  38. util::fail('没有财务权限');
  39. }
  40. $connection = Yii::$app->db;
  41. $transaction = $connection->beginTransaction();
  42. try {
  43. $shop = $this->shop;
  44. $staffId = $staff->id;
  45. $staffName = $staff->name;
  46. $params = [
  47. 'remark' => $remark,
  48. 'staffId' => $staffId,
  49. 'staffName' => $staffName,
  50. ];
  51. DeductClass::doDeduct($shop, $custom, $hd, $amount, $params);
  52. $transaction->commit();
  53. util::complete('减少成功');
  54. } catch (\Exception $exception) {
  55. $transaction->rollBack();
  56. Yii::info("减少报错:" . $exception->getMessage());
  57. util::fail('减少失败');
  58. }
  59. }
  60. }