ShopMoneyController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\shop\classes\ShopMoneyChangeClass;
  4. use bizHd\shop\classes\MainClass;
  5. use bizHd\shop\classes\ShopMoneyClass;
  6. use common\components\dict;
  7. use common\components\util;
  8. use Yii;
  9. class ShopMoneyController extends BaseController
  10. {
  11. public $guestAccess = [];
  12. public function actionMoneyChangeList()
  13. {
  14. $where = [];
  15. $where['mainId'] = $this->mainId;
  16. $list = ShopMoneyChangeClass::getChangeList($where);
  17. util::success($list);
  18. }
  19. //存入现金 20220811
  20. public function actionIn()
  21. {
  22. $get = Yii::$app->request->get();
  23. $amount = $get['amount'] ?? 0;
  24. if (is_numeric($amount) == false || $amount <= 0) {
  25. util::fail('请填写金额');
  26. }
  27. $connection = Yii::$app->db;
  28. $transaction = $connection->beginTransaction();
  29. try {
  30. $mainId = $this->mainId;
  31. $staffId = $this->shopAdminId ?? 0;
  32. $staff = $this->shopAdmin;
  33. $data = [];
  34. $data['mainId'] = $mainId;
  35. $data['sjId'] = $this->sjId;
  36. $data['amount'] = $amount;
  37. $data['staffId'] = $staffId;
  38. $data['staffName'] = $staff->name ?? '';
  39. $data['remark'] = trim($get['remark'] ?? '');
  40. $data['ptStyle'] = dict::getDict('ptStyle', 'hd');
  41. $main = MainClass::getLockById($mainId);
  42. if (empty($main)) {
  43. util::fail('没有门店信息');
  44. }
  45. ShopMoneyClass::inAmount($data, $main);
  46. $transaction->commit();
  47. util::complete();
  48. } catch (\Exception $e) {
  49. $transaction->rollBack();
  50. Yii::info("失败原因:" . $e->getMessage());
  51. util::fail('存入失败');
  52. }
  53. }
  54. //取出现金 ssh 20220811
  55. public function actionOut()
  56. {
  57. $get = Yii::$app->request->get();
  58. $amount = $get['amount'] ?? 0;
  59. if (is_numeric($amount) == false || $amount <= 0) {
  60. util::fail('请填写金额');
  61. }
  62. $connection = Yii::$app->db;
  63. $transaction = $connection->beginTransaction();
  64. try {
  65. $mainId = $this->mainId;
  66. $staffId = $this->shopAdminId ?? 0;
  67. $staff = $this->shopAdmin;
  68. $data = [];
  69. $data['mainId'] = $mainId;
  70. $data['sjId'] = $this->sjId;
  71. $data['amount'] = $amount;
  72. $data['staffId'] = $staffId;
  73. $data['staffName'] = $staff->name ?? '';
  74. $data['remark'] = trim($get['remark'] ?? '');
  75. $data['ptStyle'] = dict::getDict('ptStyle', 'hd');
  76. $main = MainClass::getLockById($mainId);
  77. if (empty($main)) {
  78. util::fail('没有门店信息');
  79. }
  80. ShopMoneyClass::outAmount($data, $main);
  81. $transaction->commit();
  82. util::complete();
  83. } catch (\Exception $e) {
  84. $transaction->rollBack();
  85. Yii::info("失败原因:" . $e->getMessage());
  86. util::fail('取出失败');
  87. }
  88. }
  89. }