ShopMoneyController.php 2.7 KB

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