MasterWorkerInfoLogic.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace app\workerapi\logic;
  3. use app\common\logic\BaseLogic;
  4. use app\common\model\bank_account\BankAccount;
  5. use app\common\model\master_worker\MasterWorkerInfo;
  6. /**
  7. * @author 林海涛
  8. * @date 2024/7/10 下午4:29
  9. */
  10. class MasterWorkerInfoLogic extends BaseLogic
  11. {
  12. public static function changeIdCard($params,$userId)
  13. {
  14. try{
  15. $where = [['worker_id', '=', $userId]];
  16. $userInfo = MasterWorkerInfo::where($where)->findOrEmpty();
  17. if ($userInfo->isEmpty()) {
  18. $userInfo = new MasterWorkerInfo();
  19. $userInfo->user_id = $userId;
  20. }
  21. $userInfo->real_name = $params['real_name'];
  22. $userInfo->id_card = $params['id_card'];
  23. $userInfo->id_card_front_img = $params['id_card_front_img'];
  24. $userInfo->id_card_opposite_img = $params['id_card_opposite_img'];
  25. $userInfo->mobile = $params['mobile'];
  26. $userInfo->address = $params['address'];
  27. $masterWorkerInfo = MasterWorkerInfo::findOrEmpty($userId);
  28. if (!$masterWorkerInfo->isEmpty()) {
  29. $masterWorkerInfo->real_name = $userInfo->real_name;
  30. $masterWorkerInfo->save();
  31. }
  32. $userInfo->save();
  33. return true;
  34. } catch(\Exception $e){
  35. self::setError($e->getMessage());
  36. return false;
  37. }
  38. }
  39. /**
  40. * 绑定银行卡
  41. * @param $params
  42. * @param $userId
  43. * @return bool
  44. * @author 林海涛
  45. * @date 2024/7/11 下午4:41
  46. */
  47. public static function bindBankAccount($params,$userId)
  48. {
  49. try{
  50. $where = [['worker_id', '=', $userId]];
  51. $bankAccount = BankAccount::where($where)->findOrEmpty();
  52. if ($bankAccount->isEmpty()) {
  53. $bankAccount = new BankAccount();
  54. $bankAccount->worker_id = $userId;
  55. }
  56. $bankAccount->account_holder = $params['account_holder'];
  57. $bankAccount->bank_name = $params['bank_name'];
  58. $bankAccount->province = $params['province'];
  59. $bankAccount->city = $params['city'];
  60. $bankAccount->opening_branch = $params['opening_branch'];
  61. $bankAccount->account = $params['account'];
  62. $bankAccount->mobile = $params['mobile'];
  63. $bankAccount->save();
  64. return true;
  65. } catch(\Exception $e){
  66. self::setError($e->getMessage());
  67. return false;
  68. }
  69. }
  70. public static function bankAccountInfo($userId)
  71. {
  72. $where = [['worker_id', '=', $userId]];
  73. return BankAccount::where($where)->withoutField(['user_id','worker_id'])->findOrEmpty()->toArray();
  74. }
  75. }