MakeSite.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. declare (strict_types = 1);
  3. namespace library\utils;
  4. // +----------------------------------------------------------------------
  5. // | [ 广告位 ]
  6. // +----------------------------------------------------------------------
  7. // | Copyright (c) 2018-2020 rights reserved.
  8. // +----------------------------------------------------------------------
  9. // | Author: TABLE ME
  10. // +----------------------------------------------------------------------
  11. // | Date: 2020-08-29 20:41
  12. // +----------------------------------------------------------------------
  13. use app\model\api\SiteProduct;
  14. use app\model\system\Advert;
  15. use \app\model\system\Advert as AdvertModel;
  16. use app\model\system\ExpCost;
  17. use app\model\system\MemberLevel;
  18. use app\model\system\Product;
  19. class MakeSite
  20. {
  21. private $sassid;
  22. /**
  23. * 生成站点数据
  24. * MakeSite constructor.
  25. * @param int $sassid
  26. */
  27. public function __construct($sassid = 0)
  28. {
  29. $this->sassid = $sassid;
  30. }
  31. /**
  32. * 生成默认数据
  33. */
  34. public function make(){
  35. $this->makeAdvert();
  36. }
  37. /**
  38. * 生成广告位
  39. */
  40. public function makeAdvert(){
  41. $adver = (new Advert)->where('is_show',1)->select();
  42. foreach ($adver as $v) {
  43. unset($v['id']);
  44. $v['sassid'] = $this->sassid;
  45. (new Advert)->insert($v);
  46. }
  47. }
  48. /**
  49. * 生成产品库
  50. */
  51. public function makeProduct(){
  52. $sitePro = new SiteProduct;
  53. $product = (new Product)->where('status',1)->select();
  54. foreach ($product as $v) {
  55. $pro = $sitePro
  56. ->where('sassid',$this->sassid)
  57. ->where('p_id',$v['id'])
  58. ->find();
  59. if(empty($pro)) {
  60. $sitePro->insert([
  61. 'p_id' => $v['id'],
  62. 'sassid' => $this->sassid,
  63. 'price' => $v['commission'],
  64. 'sales' => 0,
  65. 'ver_bug_count' => 0,
  66. 'status' => 1,
  67. 'is_host' => $v['is_host'],
  68. 'is_new' => $v['is_new'],
  69. 'cate_id' => $v['cate_id']
  70. ]);
  71. } else {
  72. $price = $v['commission'] > $pro['price'] ? $v['commission'] : $pro['price'];
  73. $sitePro
  74. ->where('sassid',$this->sassid)
  75. ->where('p_id',$v['id'])
  76. ->save(['price'=>$price]);
  77. }
  78. }
  79. }
  80. /**
  81. * 更新站邮费配置
  82. */
  83. public function makeExpcos($warehouse_id = 0) {
  84. $expCos = new ExpCost;
  85. $expData = $expCos->where('sassid',0)
  86. ->when(!empty($warehouse_id),function ($query) use($warehouse_id){
  87. $query->where('warehouse_id',$warehouse_id);
  88. })
  89. ->select();
  90. $level = (new MemberLevel)->select()->toArray();
  91. $level = array_merge([['id'=>-1,'name'=>'平台底价','code' => '']],$level);
  92. foreach ($expData as $v) {
  93. foreach ($level as $v2) {
  94. $d = $expCos
  95. ->where('warehouse_id',$v['warehouse_id'])
  96. ->where('express_id',$v['express_id'])
  97. ->where('level_id',$v2['id'])
  98. ->where('sassid',$this->sassid)
  99. ->find();
  100. //解决
  101. $d1['warehouse_id'] = $v['warehouse_id'];
  102. $d1['express_id'] = $v['express_id'];
  103. $d1['money'] = $v['money'];
  104. $d1['level_id'] = $v2['id'];
  105. $d1['sassid'] = $this->sassid;
  106. $d1['status'] = $v['status'];
  107. if(empty($d)) {
  108. $money = $expCos
  109. ->where('level_id',$v2['id'])
  110. ->where('sassid',$this->sassid)
  111. ->value('money');
  112. if(!empty($money) && $money > $d1['money']) {
  113. $d1['money'] = $money;
  114. }
  115. $expCos->insert($d1);
  116. } else {
  117. if($v['money'] > $d['money']) {
  118. $d1['money'] = $v['money'];
  119. } else {
  120. unset($d1['money']);
  121. }
  122. $expCos->where('id',$d['id'])->save($d1);
  123. }
  124. }
  125. }
  126. }
  127. }