SalaryController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\shop\classes\ShopAdminClass;
  4. use bizGhs\staff\classes\SalaryClass;
  5. use common\components\dict;
  6. use common\components\util;
  7. use Yii;
  8. class SalaryController extends BaseController
  9. {
  10. public $guestAccess = [];
  11. public function actionList()
  12. {
  13. $where = [];
  14. $where['mainId'] = $this->mainId;
  15. $list = SalaryClass::getSalaryList($where);
  16. util::success($list);
  17. }
  18. //发工资 ssh 2022710
  19. public function actionAddSalary()
  20. {
  21. $post = Yii::$app->request->post();
  22. $data = $post['data'] ?? '';
  23. if (empty($data)) {
  24. util::fail('请填写工资');
  25. }
  26. $arr = json_decode($data, true);
  27. if (is_array($arr) == false) {
  28. util::fail('请填写工资哦');
  29. }
  30. $connection = Yii::$app->db;
  31. $transaction = $connection->beginTransaction();
  32. try {
  33. $ids = array_column($arr, 'staffId');
  34. $info = ShopAdminClass::getByIds($ids, null, 'id');
  35. foreach ($arr as $item) {
  36. $staffId = $item['staffId'] ?? 0;
  37. if (isset($info[$staffId]) == false) {
  38. util::fail('员工有问题哦');
  39. }
  40. $current = $info[$staffId];
  41. $name = $current['name'] ?? '';
  42. $mobile = $current['mobile'] ?? '';
  43. $adminId = $current['adminId'] ?? 0;
  44. $amount = $item['amount'] ?? 0;
  45. $data = ['name' => $name, 'mobile' => $mobile, 'adminId' => $adminId, 'amount' => $amount, 'mainId' => $this->mainId, 'sjId' => $this->sjId];
  46. SalaryClass::addData($data);
  47. }
  48. $transaction->commit();
  49. util::complete();
  50. } catch (\Exception $e) {
  51. $transaction->rollBack();
  52. Yii::info("失败原因:" . $e->getMessage());
  53. util::fail('操作失败');
  54. }
  55. }
  56. }