DistributionApplyLogic.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\logic\distribution;
  20. use app\common\enum\DistributionApplyEnum;
  21. use app\common\enum\YesNoEnum;
  22. use app\common\logic\BaseLogic;
  23. use app\common\model\DistributionApply;
  24. use app\common\model\Distribution;
  25. use app\common\model\UserLevel;
  26. use app\common\service\RegionService;
  27. use think\facade\Db;
  28. /**
  29. * 分销申请逻辑层
  30. * Class DistributionApplyLogic
  31. * @package app\adminapi\logic\distribution
  32. */
  33. class DistributionApplyLogic extends BaseLogic
  34. {
  35. /**
  36. * @notes 查看分销申请详情
  37. * @param $params
  38. * @return mixed
  39. * @author Tab
  40. * @date 2021/7/27 15:49
  41. */
  42. public static function detail($params)
  43. {
  44. $field = 'da.real_name, da.mobile, da.province, da.city, da.district, da.reason, da.status as status_desc, da.audit_remark, da.update_time';
  45. $field .= ',u.sn, u.nickname, u.level';
  46. $detail =DistributionApply::alias('da')
  47. ->leftJoin('user u', 'u.id = da.user_id')
  48. ->field($field)
  49. ->findOrEmpty($params['id'])
  50. ->toArray();
  51. if($detail) {
  52. $detail['address'] = RegionService::getAddress([$detail['province'], $detail['city'], $detail['district']]);
  53. $detail['level_name'] = UserLevel::getLevelName($detail['level']);
  54. }
  55. return $detail;
  56. }
  57. /**
  58. * @notes 审核通过
  59. * @param $params
  60. * @return bool
  61. * @author Tab
  62. * @date 2021/7/27 16:00
  63. */
  64. public static function pass($params)
  65. {
  66. Db::startTrans();
  67. try {
  68. // 更新【分销申请表】状态
  69. $distributionAplly = DistributionApply::where('id', $params['id'])->findOrEmpty();
  70. $distributionAplly->status = DistributionApplyEnum::AUDIT_PASS;
  71. $distributionAplly->audit_remark = $params['audit_remark'] ?? '';
  72. $distributionAplly->save();
  73. // 更新【分销基础信息表】状态
  74. Distribution::where('user_id', $distributionAplly['user_id'])
  75. ->update(['is_distribution' => YesNoEnum::YES, 'distribution_time' => time()]);
  76. Db::commit();
  77. return true;
  78. } catch (\Exception $e) {
  79. Db::rollback();
  80. self::setError($e->getMessage());
  81. return false;
  82. }
  83. }
  84. /**
  85. * @notes 审核拒绝
  86. * @param $params
  87. * @author Tab
  88. * @date 2021/7/27 16:07
  89. */
  90. public static function refuse($params)
  91. {
  92. $data = [
  93. 'id' => $params['id'],
  94. 'status' => DistributionApplyEnum::AUDIT_REFUSE,
  95. 'audit_remark' => $params['audit_remark'] ?? ''
  96. ];
  97. DistributionApply::update($data);
  98. }
  99. }