MasterWorkerInfoLogic.php 2.7 KB

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