MasterWorkerInfoLogic.php 3.1 KB

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