ExpendController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 actionBx()
  39. {
  40. $get = Yii::$app->request->get();
  41. $amount = $get['amount'] ?? 0;
  42. $staffId = $get['staffId'] ?? 0;
  43. if ($amount <= 0) {
  44. util::fail('没有需要报销的金额');
  45. }
  46. $connection = Yii::$app->db;//事务处理
  47. $transaction = $connection->beginTransaction();
  48. try {
  49. $list = ExpendClass::getAllByCondition(['mainId' => $this->mainId, 'bx' => 0, 'staffId' => $staffId], null, '*', null, true);
  50. $total = 0;
  51. foreach ($list as $it) {
  52. $amount = $it->amount ?? 0;
  53. $total = bcadd($total, $amount, 2);
  54. $it->bx = 1;
  55. $it->save();
  56. }
  57. if (floatval($amount) != floatval($total)) {
  58. util::fail('金额有问题,返回上页再进来');
  59. }
  60. $transaction->commit();
  61. util::complete();
  62. } catch (\Exception $e) {
  63. $transaction->rollBack();
  64. $msg = $e->getMessage();
  65. noticeUtil::push("报销出错了,错误信息:{$msg}", '15280215347');
  66. util::fail();
  67. }
  68. }
  69. //类型列表 ssh 20240308
  70. public function actionGetTypeList()
  71. {
  72. $list = dict::getDict('expendTypeMap');
  73. util::success(['list' => $list]);
  74. }
  75. public function actionList()
  76. {
  77. $where = [];
  78. $where['mainId'] = $this->mainId;
  79. $list = ExpendClass::getExpendList($where);
  80. util::success($list);
  81. }
  82. //新增支出 ssh 20220710
  83. public function actionAddExpend()
  84. {
  85. $post = Yii::$app->request->post();
  86. $type = $post['type'] ?? 0;
  87. $amount = $post['amount'] ?? 0;
  88. $remark = $post['remark'] ?? '';
  89. if (is_numeric($amount) == false || $amount <= 0) {
  90. util::fail('请输入正确的金额');
  91. }
  92. $connection = Yii::$app->db;//事务处理
  93. $transaction = $connection->beginTransaction();
  94. try {
  95. $payWay = $post['payWay'] ?? 0;
  96. if ($payWay == dict::getDict('payWay', 'cash')) {
  97. //扣除现金
  98. $mainId = $this->mainId;
  99. $main = MainClass::getLockById($mainId);
  100. if (empty($main)) {
  101. util::fail('没有门店信息');
  102. }
  103. $balance = bcsub($main->money, $amount, 2);
  104. if ($balance < 0) {
  105. util::fail('现金不足');
  106. }
  107. $main->money = $balance;
  108. $main->save();
  109. $staffId = $this->shopAdminId;
  110. $staff = $this->shopAdmin;
  111. $staffName = $staff->name ?? '';
  112. $map = dict::getDict('expendTypeMap');
  113. $expendName = $map[$type] ?? '未知';
  114. $event = $staffName . $expendName . '支出' . $amount . '元';
  115. $capitalType = dict::getDict('capitalType', 'expendRegister', 'id');
  116. $data = [];
  117. $data['balance'] = $balance;
  118. $data['mainId'] = $mainId;
  119. $data['sjId'] = $this->sjId;
  120. $data['amount'] = $amount;
  121. $data['staffId'] = $staffId;
  122. $data['staffName'] = $staffName;
  123. $data['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  124. $data['capitalType'] = $capitalType;
  125. $data['event'] = $event;
  126. $data['remark'] = $remark;
  127. ShopMoneyClass::addData($data);
  128. }
  129. $remark = $post['remark'] ?? '';
  130. $staffName = $this->shopAdmin->name ?? '';
  131. $ptStyle = dict::getDict('ptStyle', 'ghs');
  132. $expendData = [
  133. 'type' => $type,
  134. 'amount' => $amount,
  135. 'remark' => $remark,
  136. 'mainId' => $this->mainId,
  137. 'staffId' => $this->shopAdminId,
  138. 'staffName' => $staffName,
  139. 'ptStyle' => $ptStyle,
  140. 'payWay' => $payWay,
  141. ];
  142. ExpendClass::add($expendData);
  143. $transaction->commit();
  144. util::complete();
  145. } catch (\Exception $e) {
  146. $transaction->rollBack();
  147. $msg = $e->getMessage();
  148. noticeUtil::push("登记支出失败,错误信息:{$msg}", '15280215347');
  149. }
  150. }
  151. }