ShopMoneyController.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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['ptStyle'] = dict::getDict('ptStyle', 'hd');
  40. $main = MainClass::getLockById($mainId);
  41. if (empty($main)) {
  42. util::fail('没有门店信息');
  43. }
  44. ShopMoneyClass::inAmount($data, $main);
  45. $transaction->commit();
  46. util::complete();
  47. } catch (\Exception $e) {
  48. $transaction->rollBack();
  49. Yii::info("失败原因:" . $e->getMessage());
  50. util::fail('存入失败');
  51. }
  52. }
  53. //取出现金 ssh 20220811
  54. public function actionOut()
  55. {
  56. $get = Yii::$app->request->get();
  57. $amount = $get['amount'] ?? 0;
  58. if (is_numeric($amount) == false || $amount <= 0) {
  59. util::fail('请填写金额');
  60. }
  61. $connection = Yii::$app->db;
  62. $transaction = $connection->beginTransaction();
  63. try {
  64. $mainId = $this->mainId;
  65. $staffId = $this->shopAdminId ?? 0;
  66. $staff = $this->shopAdmin;
  67. $data = [];
  68. $data['mainId'] = $mainId;
  69. $data['sjId'] = $this->sjId;
  70. $data['amount'] = $amount;
  71. $data['staffId'] = $staffId;
  72. $data['staffName'] = $staff->name ?? '';
  73. $data['ptStyle'] = dict::getDict('ptStyle', 'hd');
  74. $main = MainClass::getLockById($mainId);
  75. if (empty($main)) {
  76. util::fail('没有门店信息');
  77. }
  78. ShopMoneyClass::outAmount($data, $main);
  79. $transaction->commit();
  80. util::complete();
  81. } catch (\Exception $e) {
  82. $transaction->rollBack();
  83. Yii::info("失败原因:" . $e->getMessage());
  84. util::fail('取出失败');
  85. }
  86. }
  87. }