截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Center.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\admin\controller\distribution;
  3. use app\admin\logic\distribution\CenterLogic;
  4. use app\common\basics\AdminBase;
  5. use app\common\model\distribution\Distribution;
  6. use app\common\model\distribution\DistributionLevel;
  7. use app\common\model\user\User;
  8. use app\common\server\JsonServer;
  9. use app\common\model\distribution\DistributionOrderGoods;
  10. class Center extends AdminBase
  11. {
  12. public function data()
  13. {
  14. // 已结算: 已结算
  15. $settled = DistributionOrderGoods::where(['status'=>2])->sum('money');
  16. // 预估: 待返佣 + 已结算
  17. $estimate = DistributionOrderGoods::where('status', 'in', [1, 2])->sum('money');
  18. return view('', [
  19. 'settled' => $settled,
  20. 'estimate' => $estimate
  21. ]);
  22. }
  23. /**
  24. * @notes 数据概览
  25. * @return \think\response\Json
  26. * @author Tab
  27. * @date 2021/9/6 14:35
  28. */
  29. public function center()
  30. {
  31. $data = CenterLogic::center();
  32. return view('', ['data' => $data]);
  33. }
  34. /**
  35. * @notes 分销初始化数据
  36. * @return \think\response\Json
  37. * @author Tab
  38. * @date 2021/9/6 14:26
  39. */
  40. public function updateTable()
  41. {
  42. try {
  43. $defaultLevel = DistributionLevel::where('is_default', 1)->findOrEmpty()->toArray();
  44. if (empty($defaultLevel)) {
  45. // 没有默认等级,初始化
  46. DistributionLevel::create([
  47. 'name' => '默认等级',
  48. 'weights' => '1',
  49. 'is_default' => '1',
  50. 'remark' => '默认等级',
  51. 'update_relation' => '1'
  52. ]);
  53. }
  54. // 默认分销会员等级
  55. $defaultLevelId = DistributionLevel::where('is_default', 1)->value('id');
  56. // 生成分销基础信息表
  57. $users = User::field('id,is_distribution')
  58. ->where(['del' => 0])
  59. ->select()
  60. ->toArray();
  61. $distribution = Distribution::column('user_id');
  62. $addData = [];
  63. foreach($users as $item) {
  64. if (in_array($item['id'], $distribution)) {
  65. // 已有基础分销记录,跳过
  66. continue;
  67. }
  68. $data = [
  69. 'user_id' => $item['id'],
  70. 'level_id' => $defaultLevelId,
  71. 'is_distribution' => $item['is_distribution'],
  72. 'is_freeze' => 0,
  73. 'remark' => '',
  74. ];
  75. $addData[] = $data;
  76. }
  77. $distributionModel = new Distribution();
  78. $distributionModel->saveAll($addData);
  79. return JsonServer::success('初始化数据完成');
  80. } catch(\Exception $e) {
  81. return JsonServer::error($e->getMessage());
  82. }
  83. }
  84. }