DeductController.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. util::fail('即将上线');
  15. $post = Yii::$app->request->post();
  16. $customId = $post['customId'] ?? 0;
  17. $remark = $post['remark'] ?? '';
  18. $custom = CustomClass::getByID($customId, true);
  19. if (empty($custom)) {
  20. util::fail('没有找到客户');
  21. }
  22. if ($custom->shopId != $this->shopId) {
  23. util::fail('不是你的客户');
  24. }
  25. $hdId = $custom->hdId;
  26. $hd = HdClass::getByID($hdId, true);
  27. if (empty($hd)) {
  28. util::fail('客户信息缺失,编号7756');
  29. }
  30. $amount = $post['amount'] ?? 0;
  31. if (empty($amount)) {
  32. util::fail('请填写金额');
  33. }
  34. if ($amount < 0) {
  35. util::fail('金额要大于0');
  36. }
  37. $staff = $this->shopAdmin;
  38. if ($staff->finance == 0) {
  39. util::fail('没有财务权限');
  40. }
  41. $connection = Yii::$app->db;
  42. $transaction = $connection->beginTransaction();
  43. try {
  44. $shop = $this->shop;
  45. $staffId = $staff->id;
  46. $staffName = $staff->name;
  47. $params = [
  48. 'remark' => $remark,
  49. 'staffId' => $staffId,
  50. 'staffName' => $staffName,
  51. ];
  52. DeductClass::doDeduct($shop, $custom, $hd, $amount, $params);
  53. $transaction->commit();
  54. util::complete('减少成功');
  55. } catch (\Exception $exception) {
  56. $transaction->rollBack();
  57. Yii::info("减少报错:" . $exception->getMessage());
  58. util::fail('减少失败');
  59. }
  60. }
  61. }