ExpendController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\expend\classes\ExpendClass;
  4. use bizGhs\shop\classes\MainClass;
  5. use bizGhs\shop\classes\ShopAdminClass;
  6. use bizGhs\shop\classes\ShopMoneyClass;
  7. use common\components\dict;
  8. use common\components\noticeUtil;
  9. use common\components\util;
  10. use Yii;
  11. class ExpendController extends BaseController
  12. {
  13. //待报销人员列表和金额 ssh 20240308
  14. public function actionUnBxList()
  15. {
  16. ini_set('memory_limit', '2045M');
  17. set_time_limit(0);
  18. $list = ExpendClass::getAllByCondition(['mainId' => $this->mainId, 'bx' => 0], null, '*', null);
  19. $arr = [];
  20. if (!empty($list)) {
  21. foreach ($list as $expend) {
  22. $staffId = $expend['staffId'] ?? 0;
  23. $amount = $expend['amount'] ?? 0;
  24. $staffName = $expend['staffName'] ?? '';
  25. if (isset($arr[$staffId])) {
  26. $arr[$staffId]['amount'] = bcadd($arr[$staffId]['amount'], $amount);
  27. $arr[$staffId]['num'] = bcadd($arr[$staffId]['num'], 1);
  28. } else {
  29. $arr[$staffId]['amount'] = $amount;
  30. $arr[$staffId]['staffName'] = $staffName;
  31. $arr[$staffId]['num'] = 1;
  32. }
  33. }
  34. }
  35. util::success(['list' => $arr]);
  36. }
  37. //类型列表 ssh 20240308
  38. public function actionGetTypeList()
  39. {
  40. $list = dict::getDict('expendTypeMap');
  41. util::success(['list' => $list]);
  42. }
  43. public function actionList()
  44. {
  45. $where = [];
  46. $where['mainId'] = $this->mainId;
  47. $list = ExpendClass::getExpendList($where);
  48. util::success($list);
  49. }
  50. //新增支出 ssh 20220710
  51. public function actionAddExpend()
  52. {
  53. $post = Yii::$app->request->post();
  54. $type = $post['type'] ?? 0;
  55. $amount = $post['amount'] ?? 0;
  56. $remark = $post['remark'] ?? '';
  57. if (is_numeric($amount) == false || $amount <= 0) {
  58. util::fail('请输入正确的金额');
  59. }
  60. $connection = Yii::$app->db;//事务处理
  61. $transaction = $connection->beginTransaction();
  62. try {
  63. $payWay = $post['payWay'] ?? 0;
  64. if ($payWay == dict::getDict('payWay', 'cash')) {
  65. //扣除现金
  66. $mainId = $this->mainId;
  67. $main = MainClass::getLockById($mainId);
  68. if (empty($main)) {
  69. util::fail('没有门店信息');
  70. }
  71. $balance = bcsub($main->money, $amount, 2);
  72. if ($balance < 0) {
  73. util::fail('现金不足');
  74. }
  75. $main->money = $balance;
  76. $main->save();
  77. $staffId = $this->shopAdminId;
  78. $staff = $this->shopAdmin;
  79. $staffName = $staff->name ?? '';
  80. $map = dict::getDict('expendTypeMap');
  81. $expendName = $map[$type] ?? '未知';
  82. $event = $staffName . $expendName . '支出' . $amount . '元';
  83. $capitalType = dict::getDict('capitalType', 'expendRegister', 'id');
  84. $data = [];
  85. $data['balance'] = $balance;
  86. $data['mainId'] = $mainId;
  87. $data['sjId'] = $this->sjId;
  88. $data['amount'] = $amount;
  89. $data['staffId'] = $staffId;
  90. $data['staffName'] = $staffName;
  91. $data['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  92. $data['capitalType'] = $capitalType;
  93. $data['event'] = $event;
  94. $data['remark'] = $remark;
  95. ShopMoneyClass::addData($data);
  96. }
  97. $remark = $post['remark'] ?? '';
  98. $staffName = $this->shopAdmin->name ?? '';
  99. $ptStyle = dict::getDict('ptStyle', 'ghs');
  100. $expendData = [
  101. 'type' => $type,
  102. 'amount' => $amount,
  103. 'remark' => $remark,
  104. 'mainId' => $this->mainId,
  105. 'staffId' => $this->shopAdminId,
  106. 'staffName' => $staffName,
  107. 'ptStyle' => $ptStyle,
  108. 'payWay' => $payWay,
  109. ];
  110. ExpendClass::add($expendData);
  111. $transaction->commit();
  112. util::complete();
  113. } catch (\Exception $e) {
  114. $transaction->rollBack();
  115. $msg = $e->getMessage();
  116. noticeUtil::push("登记支出失败,错误信息:{$msg}", '15280215347');
  117. }
  118. }
  119. }