ActivityApplyGoods.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Author: 芸众商城 www.yunzshop.com
  4. * Date: 2017/8/2
  5. * Time: 下午2:33
  6. */
  7. namespace Yunshop\ActivityApply\common\models;
  8. use app\common\models\BaseModel;
  9. class ActivityApplyGoods extends BaseModel
  10. {
  11. public $table = 'yz_activity_apply_goods';
  12. public $timestamps = true;
  13. protected $guarded = [''];
  14. static protected $needLog = true;
  15. protected $casts = [
  16. 'payment_types' => 'json'
  17. ];
  18. public function scopeByGoodsId($query, $goods_id)
  19. {
  20. return $query->where('goods_id', $goods_id);
  21. }
  22. public $attributes = [
  23. 'is_open' => 0,
  24. 'plugins' => [
  25. 'love' => [
  26. 'deduction_proportion' => 0,
  27. "award_proportion" => 0,
  28. "award_shop" => 0
  29. ]
  30. ],
  31. 'profit' => [
  32. 'commission' => [
  33. 'amount' => 0
  34. ],
  35. 'team-dividend' => [
  36. 'amount' => 0
  37. ],
  38. 'area-dividend' => [
  39. 'amount' => 0
  40. ],
  41. 'merchant-staff' => [
  42. 'amount' => 0
  43. ],
  44. 'merchant-center' => [
  45. 'amount' => 0
  46. ],
  47. 'single-return' => [
  48. 'amount' => 0
  49. ],
  50. 'full-return' => [
  51. 'is_open' => 0
  52. ],
  53. 'consume-return' => [
  54. 'is_open' => 0
  55. ]
  56. ]
  57. ];
  58. public static function relationSave($goodsId, $data, $operate)
  59. {
  60. if (!$goodsId) {
  61. return false;
  62. }
  63. if (!$data) {
  64. return false;
  65. }
  66. $saleModel = self::getModel($goodsId, $operate);
  67. //判断deleted
  68. if ($operate == 'deleted') {
  69. return $saleModel->delete();
  70. }
  71. foreach ($data['coupon_ids'] as $key_id => $id) {
  72. $data['coupon'][] = [
  73. 'id' => $id,
  74. 'name' => $data['coupon_names'][$key_id]
  75. ];
  76. }
  77. $data['goods_id'] = $goodsId;
  78. $data['plugins'] = serialize($data['plugins']);
  79. $data['profit'] = serialize($data['profit']);
  80. $data['coupon'] = serialize($data['coupon']);
  81. unset($data['coupon_ids']);
  82. unset($data['coupon_names']);
  83. $saleModel->fill($data);
  84. return $saleModel->save();
  85. }
  86. public static function getModel($goodsId, $operate)
  87. {
  88. $model = false;
  89. if ($operate != 'created') {
  90. $model = static::where(['goods_id' => $goodsId])->first();
  91. }
  92. !$model && $model = new static;
  93. return $model;
  94. }
  95. public function getDeductWidgets($widgets)
  96. {
  97. //积分
  98. $point = trim($widgets['sale']['point']);
  99. if (!$point) {
  100. $point = 0;
  101. }
  102. $widgets['sale']['point'] = $point .'%';
  103. $widgets['sale']['award_balance'] = $widgets['sale']['award_balance']?:0;
  104. $max_point_deduct = trim($widgets['sale']['max_point_deduct']);
  105. if (!$max_point_deduct) {
  106. $max_point_deduct = 0;
  107. }
  108. $widgets['sale']['max_point_deduct'] = $max_point_deduct .'%';
  109. $min_point_deduct = trim($widgets['sale']['min_point_deduct']);
  110. if (!$min_point_deduct) {
  111. $min_point_deduct = 0;
  112. }
  113. $widgets['sale']['min_point_deduct'] = $min_point_deduct .'%';
  114. //分享描述
  115. $widgets['share']['share_title'] = $widgets['share']['share_title'];
  116. $widgets['share']['share_thumb'] = $widgets['share']['share_thumb'];
  117. $widgets['share']['share_desc'] = $widgets['share']['share_desc'];
  118. //爱心值
  119. $exist_love = app('plugins')->isEnabled('love');
  120. if ($exist_love) {
  121. $widgets['love']['award'] = trim($widgets['love']['award']) ? trim($widgets['love']['award']) : 0;//爱心值奖励是否开启
  122. $widgets['love']['deduction'] = trim($widgets['love']['deduction']) ? trim($widgets['love']['deduction']) : 0;//爱心值抵扣是否开启
  123. $widgets['love']['parent_award'] = trim($widgets['love']['parent_award']) ? trim($widgets['love']['parent_award']) : 0;//爱心值上级奖励是否开启
  124. $widgets['love']['deduction_proportion'] = trim($widgets['love']['deduction_proportion']) ? trim($widgets['love']['deduction_proportion']) : 0;//爱心值最高抵扣
  125. $widgets['love']['award_proportion'] = trim($widgets['love']['award_proportion']) ? trim($widgets['love']['award_proportion']) : 0;//爱心值奖励
  126. if($widgets['love']['deduction_proportion'] == 0){
  127. $widgets['love']['deduction'] = 0;
  128. }
  129. if($widgets['love']['award_proportion'] == 0){
  130. $widgets['love']['award'] = 0;
  131. }
  132. $widgets['love']['parent_award_proportion'] = trim($widgets['love']['parent_award_proportion']) ? trim($widgets['love']['parent_award_proportion']) : 0;//爱心值上级第一级奖励
  133. $widgets['love']['second_award_proportion'] = trim($widgets['love']['second_award_proportion']) ? trim($widgets['love']['second_award_proportion']) : 0;//爱心值上级第二级奖励
  134. }
  135. //经销商
  136. $exist_team_dividend = app('plugins')->isEnabled('team-dividend');
  137. if ($exist_team_dividend) {
  138. $widgets['team_dividend']['is_dividend'] = trim($widgets['team_dividend']['is_dividend']) ? trim($widgets['team_dividend']['is_dividend']) : 0;
  139. if($widgets['team_dividend']['is_dividend'] == 1){
  140. $widgets['team_dividend']['has_dividend'] = 1;
  141. }else{
  142. $widgets['team_dividend']['has_dividend'] = 0;
  143. }
  144. $widgets['team_dividend']['has_dividend_rate'] = trim($widgets['team_dividend']['has_dividend_rate']) ? trim($widgets['team_dividend']['has_dividend_rate']) : 0;
  145. }
  146. //消费赠送
  147. $exist_single_return = app('plugins')->isEnabled('single-return');
  148. if ($exist_single_return) {
  149. $widgets['single_return']['return_rate'] = trim($widgets['single_return']['return_rate']) ? trim($widgets['single_return']['return_rate']) : 0;
  150. if( $widgets['single_return']['return_rate'] == 0){
  151. $widgets['single_return']['is_single_return'] = 0;
  152. }else{
  153. $widgets['single_return']['is_single_return'] = 1;
  154. }
  155. }
  156. return $widgets;
  157. }
  158. }