SalaryController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. $staff = $this->shopAdmin;
  14. $mobile = $staff->mobile ?? 0;
  15. if (in_array($mobile, ['15280215347', '13531700113', '18030262314']) == false) {
  16. util::fail('没有权限');
  17. }
  18. $where = [];
  19. $where['mainId'] = $this->mainId;
  20. $list = SalaryClass::getSalaryList($where);
  21. util::success($list);
  22. }
  23. //发工资 ssh 2022710
  24. public function actionAddSalary()
  25. {
  26. $staff = $this->shopAdmin;
  27. $mobile = $staff->mobile ?? 0;
  28. if (in_array($mobile, ['15280215347', '13531700113', '18030262314']) == false) {
  29. util::fail('没有权限');
  30. }
  31. $post = Yii::$app->request->post();
  32. $data = $post['data'] ?? '';
  33. if (empty($data)) {
  34. util::fail('请填写工资');
  35. }
  36. $arr = json_decode($data, true);
  37. if (is_array($arr) == false) {
  38. util::fail('请填写工资哦');
  39. }
  40. $connection = Yii::$app->db;
  41. $transaction = $connection->beginTransaction();
  42. try {
  43. $ids = array_column($arr, 'staffId');
  44. $info = ShopAdminClass::getByIds($ids, null, 'id');
  45. foreach ($arr as $item) {
  46. $staffId = $item['staffId'] ?? 0;
  47. if (isset($info[$staffId]) == false) {
  48. util::fail('员工有问题哦');
  49. }
  50. $current = $info[$staffId];
  51. $name = $current['name'] ?? '';
  52. $mobile = $current['mobile'] ?? '';
  53. $adminId = $current['adminId'] ?? 0;
  54. $amount = $item['amount'] ?? 0;
  55. $data = ['name' => $name, 'mobile' => $mobile, 'adminId' => $adminId, 'amount' => $amount, 'mainId' => $this->mainId, 'sjId' => $this->sjId];
  56. SalaryClass::addData($data);
  57. }
  58. $transaction->commit();
  59. util::complete();
  60. } catch (\Exception $e) {
  61. $transaction->rollBack();
  62. Yii::info("失败原因:" . $e->getMessage());
  63. util::fail('操作失败');
  64. }
  65. }
  66. }