MasterWorkerInfoLogic.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. $masterWorker = MasterWorker::findOrEmpty($userId);
  33. if (!$masterWorker->isEmpty()) {
  34. $masterWorker->real_name = $userInfo->real_name;
  35. $masterWorker->save();
  36. }
  37. $userInfo->save();
  38. return true;
  39. } catch(\Exception $e){
  40. self::setError($e->getMessage());
  41. return false;
  42. }
  43. }
  44. /**
  45. * 绑定银行卡
  46. * @param $params
  47. * @param $userId
  48. * @return bool
  49. * @author 林海涛
  50. * @date 2024/7/11 下午4:41
  51. */
  52. public static function bindBankAccount($params,$userId)
  53. {
  54. try{
  55. $where = [['worker_id', '=', $userId]];
  56. $bankAccount = BankAccount::where($where)->findOrEmpty();
  57. if ($bankAccount->isEmpty()) {
  58. $bankAccount = new BankAccount();
  59. $bankAccount->worker_id = $userId;
  60. }
  61. $bankAccount->account_holder = $params['account_holder'];
  62. $bankAccount->bank_name = $params['bank_name'];
  63. $bankAccount->province = $params['province'];
  64. $bankAccount->city = $params['city'];
  65. $bankAccount->opening_branch = $params['opening_branch'];
  66. $bankAccount->account = $params['account'];
  67. $bankAccount->mobile = $params['mobile'];
  68. $bankAccount->bank_image = !empty($params['bank_image'])?$params['bank_image']:'';
  69. $bankAccount->save();
  70. return true;
  71. } catch(\Exception $e){
  72. self::setError($e->getMessage());
  73. return false;
  74. }
  75. }
  76. public static function bankAccountInfo($userId)
  77. {
  78. $where = [['worker_id', '=', $userId]];
  79. return BankAccount::where($where)->withoutField(['user_id','worker_id'])->findOrEmpty()->toArray();
  80. }
  81. }