SpreadApplyServices.php 3.7 KB

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