SpreadApplyServices.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\services\agent;
  3. use app\dao\agent\SpreadApplyDao;
  4. use app\services\BaseServices;
  5. use app\services\other\AgreementServices;
  6. use app\services\user\UserServices;
  7. use crmeb\exceptions\ApiException;
  8. class SpreadApplyServices extends BaseServices
  9. {
  10. public function __construct(SpreadApplyDao $dao)
  11. {
  12. $this->dao = $dao;
  13. }
  14. public function applyList($where)
  15. {
  16. [$page, $limit] = $this->getPageValue();
  17. $list = $this->dao->applyList($where, $page, $limit);
  18. foreach ($list as &$item) {
  19. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  20. $item['status_time'] = date('Y-m-d H:i:s', $item['status_time']);
  21. }
  22. $count = $this->dao->applyCount($where);
  23. return compact('list', 'count');
  24. }
  25. public function applyExamine($id, $uid, $status, $refusal_reason = '')
  26. {
  27. $this->dao->update(['id' => $id], ['status' => $status, 'status_time' => time(), 'refusal_reason' => $refusal_reason]);
  28. if ($status == 1) {
  29. app()->make(UserServices::class)->update(['uid' => $uid], ['is_promoter' => 1]);
  30. }
  31. return true;
  32. }
  33. public function applyDelete($id)
  34. {
  35. $this->dao->delete($id);
  36. return true;
  37. }
  38. public function applyInfo($uid)
  39. {
  40. $applyInfo = $this->dao->get(['uid' => $uid, 'is_del' => 0]);
  41. $userInfo = app()->make(UserServices::class)->get($uid);
  42. $user = [
  43. 'id' => $applyInfo['id'] ?? 0,
  44. 'uid' => $uid,
  45. 'nickname' => $userInfo['nickname'] ?? '',
  46. 'real_name' => $userInfo['real_name'] ?? '',
  47. 'phone' => $userInfo['phone'] ?? '',
  48. 'content' => $userInfo['content'] ?? '',
  49. 'status' => $applyInfo ? $applyInfo['status'] : -1,
  50. 'add_time' => $applyInfo ? date('Y/m/d H:i', $applyInfo['add_time']) : '',
  51. 'status_time' => isset($applyInfo['status_time']) ? date('Y/m/d H:i', $applyInfo['status_time']) : '',
  52. 'refusal_reason' => $applyInfo['refusal_reason'] ?? '',
  53. ];
  54. $agreement = app()->make(AgreementServices::class)->getAgreementBytype(8);
  55. return compact('user', 'agreement');
  56. }
  57. public function applyPromoter($data, $id, $userInfo)
  58. {
  59. if (!sys_config('brokerage_func_status')) throw new ApiException('未开启推广功能');
  60. if (sys_config('store_brokerage_statu') != 1) throw new ApiException('非指定分销模式无需申请推广员');
  61. if ($userInfo['is_promoter']) throw new ApiException('您已经是推广员');
  62. if ($data['phone'] != $userInfo['phone']) {
  63. $phoneUsed = app()->make(UserServices::class)->count(['phone' => $data['phone']]);
  64. if ($phoneUsed) throw new ApiException('该手机号已被使用');
  65. }
  66. if ($id) {
  67. $data['status'] = 0;
  68. $res = $this->dao->update(['id' => $id], $data);
  69. } else {
  70. $data['add_time'] = time();
  71. $res = $this->dao->save($data);
  72. $id = $res->id;
  73. }
  74. if (!$res) throw new ApiException('申请失败');
  75. return $id;
  76. }
  77. }