DeductController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 actionDeductBalance()
  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('客户信息缺失');
  28. }
  29. $amount = $post['amount'] ?? 0;
  30. if (empty($amount)) {
  31. util::fail('请填写金额');
  32. }
  33. if ($amount < 0) {
  34. util::fail('金额要大于0');
  35. }
  36. $shop = $this->shop;
  37. $staff = $this->shopAdmin;
  38. $staffId = $staff->id;
  39. $staffName = $staff->name;
  40. $params = [
  41. 'remark' => $remark,
  42. 'staffId' => $staffId,
  43. 'staffName' => $staffName,
  44. ];
  45. DeductClass::doDeduct($shop, $custom, $hd, $amount, $params);
  46. util::complete('减少成功');
  47. }
  48. }