2019_07_05_151900_remove_third_level.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. use app\common\models\UniAccount;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Database\Migrations\Migration;
  5. class RemoveThirdLevel extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. *
  10. * @return void
  11. */
  12. public function up()
  13. {
  14. if (Schema::hasTable('yz_setting')) {
  15. $uniAccount = UniAccount::getEnable();
  16. foreach ($uniAccount as $u) {
  17. \YunShop::app()->uniacid = $u->uniacid;
  18. \Setting::$uniqueAccountId = $u->uniacid;
  19. $this->updateCommission();
  20. $this->updateMicro();
  21. $this->updateClock();
  22. $this->updateCar();
  23. $this->updateHotel();
  24. $this->updateStore();
  25. $this->updateLove();
  26. $this->updateAsset();
  27. }
  28. }
  29. }
  30. /**
  31. * Reverse the migrations.
  32. *
  33. * @return void
  34. */
  35. public function down()
  36. {
  37. }
  38. public function updateCommission()
  39. {
  40. if (app('plugins')->isEnabled('commission')) {
  41. $plugin = \Setting::get('plugin.commission');
  42. if (!$plugin) {
  43. return;
  44. }
  45. if ($plugin['goods_detail_level'] == 3) {
  46. $plugin['goods_detail_level'] = 2;
  47. }
  48. if ($plugin['level'] == 3) {
  49. $plugin['level'] = 2;
  50. unset($plugin['third_level']);
  51. }
  52. \Setting::set('plugin.commission', $plugin);
  53. $commissionNotice = \Setting::get('plugin.commission_notice');
  54. $temp_id = $commissionNotice['commission_upgrade'];
  55. if (!is_null( \app\common\models\notice\MessageTemp::find($temp_id))) {
  56. \app\common\models\notice\MessageTemp::where('id',$temp_id) ->delete();
  57. }
  58. }
  59. }
  60. public function updateMicro()
  61. {
  62. if (app('plugins')->isEnabled('micro')) {
  63. $plugin = \Setting::get('plugin.micro');
  64. if (!$plugin) {
  65. return;
  66. }
  67. if ($plugin['agent_bonus_level'] >= 2 ) {
  68. $plugin['agent_bonus_level'] = 1;
  69. unset($plugin['bonus_third_level']);
  70. unset($plugin['gold_second_level']);
  71. }
  72. unset($plugin['agent_gold_level']);
  73. unset($plugin['gold_first_level']);
  74. unset($plugin['gold_second_level']);
  75. unset($plugin['gold_third_level']);
  76. \Setting::set('plugin.micro', $plugin);
  77. }
  78. }
  79. public function updateClock()
  80. {
  81. if (app('plugins')->isEnabled('clock-in')) {
  82. $plugin = \Setting::get('plugin.clock_in');
  83. if (!$plugin) {
  84. return;
  85. }
  86. if ($plugin['level'] == 3) {
  87. $plugin['level'] = 2;
  88. unset($plugin['third_level']);
  89. }
  90. foreach ($plugin['commission_level'] as $key => $level) {
  91. unset($plugin['commission_level'][$key]['third_level']);
  92. }
  93. \Setting::set('plugin.clock_in', $plugin);
  94. }
  95. }
  96. public function updateCar()
  97. {
  98. if (app('plugins')->isEnabled('net-car')) {
  99. $plugin = \Setting::get('plugin.net_car');
  100. if (!$plugin) {
  101. return;
  102. }
  103. unset($plugin['user_referrer_rate']['three']);
  104. \Setting::set('plugin.net_car', $plugin);
  105. }
  106. }
  107. public function updateStore()
  108. {
  109. if (app('plugins')->isEnabled('store-cashier')) {
  110. $stores = \Yunshop\StoreCashier\common\models\StoreSetting::where('key','commission')->get();
  111. if ($stores->isEmpty()) {
  112. return;
  113. }
  114. foreach ($stores as $store) {
  115. $commission = $store->value;
  116. if ($commission['level'] == 3) {
  117. $commission['level'] = 2;
  118. unset($commission['third_level']);
  119. }
  120. foreach ($commission['rule'] as $key => $level) {
  121. unset($commission['rule'][$key]['third_level_rate']);
  122. }
  123. $store->value = $commission;
  124. $store->save();
  125. }
  126. }
  127. }
  128. public function updateHotel()
  129. {
  130. if (app('plugins')->isEnabled('hotel')) {
  131. $hotels = \Yunshop\Hotel\common\models\HotelSetting::where('key','commission')->get();
  132. if ($hotels->isEmpty()) {
  133. return;
  134. }
  135. foreach ($hotels as $hotel) {
  136. $commission = $hotel->value;
  137. if ($commission['level'] == 3) {
  138. $commission['level'] = 2;
  139. unset($commission['third_level']);
  140. }
  141. foreach ($commission['rule'] as $key => $level) {
  142. unset($commission['rule'][$key]['third_level_rate']);
  143. }
  144. $hotel->value = $commission;
  145. $hotel->save();
  146. }
  147. }
  148. }
  149. public function updateLove()
  150. {
  151. if (app('plugins')->isEnabled('love')) {
  152. $goods_love = \Yunshop\Love\Common\Models\GoodsLove::uniacid()->where('goods_id',96)->get();
  153. if (!$goods_love->isEmpty()) {
  154. foreach ($goods_love as $love) {
  155. $love->third_award_proportion = 0;
  156. $love->third_award_fixed = 0;
  157. if ($love->commission) {
  158. $commission = unserialize($love->commission);
  159. foreach ($commission['rule'] as $key => $level) {
  160. unset($commission['rule'][$key]['third_level_rate']);
  161. unset($commission['rule'][$key]['third_level_fixed']);
  162. }
  163. $love->commission = serialize($commission);
  164. }
  165. $love->save();
  166. }
  167. }
  168. $plugin = array_pluck(\Setting::getAllByGroup('Love')->toArray(), 'value', 'key');
  169. if ($plugin['third_award_proportion']) {
  170. $plugin['third_award_proportion'] = 0;
  171. }
  172. if ($plugin['commission']) {
  173. $plugin['commission'] = unserialize($plugin['commission']);
  174. foreach ($plugin['commission']['rule'] as $key => $commission) {
  175. unset($plugin['commission']['rule'][$key]['third_level_rate']);
  176. }
  177. $plugin['commission'] = serialize($plugin['commission']);
  178. }
  179. foreach ($plugin as $key => $item) {
  180. \Setting::set('love.' . $key, $item);
  181. }
  182. }
  183. }
  184. public function updateAsset()
  185. {
  186. if (app('plugins')->isEnabled('asset')) {
  187. $assets = \Yunshop\Asset\Common\Models\AssetDigitizationModel::select(['goods_id','sell_goods'])->uniacid()->get();
  188. if (!$assets->isEmpty()) {
  189. return;
  190. }
  191. $assets = $assets->toArray();
  192. $goods_id = array_column($assets,'goods_id');
  193. $sell_goods = array_column($assets, 'sell_goods');
  194. $love_goods = array_merge($goods_id, $sell_goods);
  195. if (app('plugins')->isEnabled('team-dividend')) {
  196. \Yunshop\TeamDividend\models\GoodsTeamDividend::whereIn('goods_id',$goods_id)->delete();
  197. }
  198. if (app('plugins')->isEnabled('commission')) {
  199. \Yunshop\Commission\models\Commission::whereIn('goods_id',$goods_id)->delete();
  200. }
  201. if (app('plugins')->isEnabled('area-dividend')) {
  202. \Yunshop\AreaDividend\models\AreaDividendGoods::whereIn('goods_id',$goods_id)->delete();
  203. }
  204. if (app('plugins')->isEnabled('love')) {
  205. \Yunshop\Love\Common\Models\GoodsLove::whereIn('goods_id',$love_goods)->delete();
  206. }
  207. }
  208. }
  209. }