ExpendController.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\expend\classes\ExpendClass;
  4. use bizGhs\shop\classes\MainClass;
  5. use bizGhs\shop\classes\ShopMoneyClass;
  6. use common\components\dict;
  7. use common\components\noticeUtil;
  8. use common\components\util;
  9. use Yii;
  10. class ExpendController extends BaseController
  11. {
  12. public function actionList()
  13. {
  14. $where = [];
  15. $where['mainId'] = $this->mainId;
  16. $list = ExpendClass::getExpendList($where);
  17. util::success($list);
  18. }
  19. //新增支出 ssh 20220710
  20. public function actionAddExpend()
  21. {
  22. $post = Yii::$app->request->post();
  23. $type = $post['type'] ?? 0;
  24. $amount = $post['amount'] ?? 0;
  25. $remark = $post['remark'] ?? '';
  26. if (is_numeric($amount) == false || $amount <= 0) {
  27. util::fail('请输入正确的金额');
  28. }
  29. $connection = Yii::$app->db;//事务处理
  30. $transaction = $connection->beginTransaction();
  31. try {
  32. $payWay = $post['payWay'] ?? 0;
  33. if ($payWay == dict::getDict('payWay', 'cash')) {
  34. //扣除现金
  35. $mainId = $this->mainId;
  36. $main = MainClass::getLockById($mainId);
  37. if (empty($main)) {
  38. util::fail('没有门店信息');
  39. }
  40. $hasMoney = $main->money ?? 0;
  41. if ($amount > $hasMoney) {
  42. util::fail('现金不足');
  43. }
  44. $staffId = $this->shopAdminId;
  45. $staff = $this->shopAdmin;
  46. $staffName = $staff->name ?? '';
  47. $map = dict::getDict('expendTypeMap');
  48. $expendName = $map[$type] ?? '未知';
  49. $event = $staffName . $expendName . '支出' . $amount . '元';
  50. $capitalType = dict::getDict('capitalType', 'expendRegister', 'id');
  51. $data = [];
  52. $data['mainId'] = $mainId;
  53. $data['sjId'] = $this->sjId;
  54. $data['amount'] = $amount;
  55. $data['staffId'] = $staffId;
  56. $data['staffName'] = $staffName;
  57. $data['ptStyle'] = dict::getDict('ptStyle', 'ghs');
  58. $data['capitalType'] = $capitalType;
  59. $data['event'] = $event;
  60. $data['remark'] = $remark;
  61. ShopMoneyClass::addData($data);
  62. }
  63. $remark = $post['remark'] ?? '';
  64. $staffName = $this->shopAdmin->name ?? '';
  65. $ptStyle = dict::getDict('ptStyle', 'ghs');
  66. $expendData = [
  67. 'type' => $type,
  68. 'amount' => $amount,
  69. 'remark' => $remark,
  70. 'mainId' => $this->mainId,
  71. 'staffId' => $this->shopAdminId,
  72. 'staffName' => $staffName,
  73. 'ptStyle' => $ptStyle,
  74. ];
  75. ExpendClass::add($expendData);
  76. $transaction->commit();
  77. util::complete();
  78. } catch (\Exception $e) {
  79. $transaction->rollBack();
  80. $msg = $e->getMessage();
  81. noticeUtil::push("登记支出失败,错误信息:{$msg}", '15280215347');
  82. }
  83. }
  84. }