| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- /**
- * Author: 芸众商城 www.yunzshop.com
- * Date: 2017/8/2
- * Time: 下午2:33
- */
- namespace Yunshop\ActivityApply\common\models;
- use app\common\models\BaseModel;
- class ActivityApplyGoods extends BaseModel
- {
- public $table = 'yz_activity_apply_goods';
- public $timestamps = true;
- protected $guarded = [''];
- static protected $needLog = true;
- protected $casts = [
- 'payment_types' => 'json'
- ];
- public function scopeByGoodsId($query, $goods_id)
- {
- return $query->where('goods_id', $goods_id);
- }
- public $attributes = [
- 'is_open' => 0,
- 'plugins' => [
- 'love' => [
- 'deduction_proportion' => 0,
- "award_proportion" => 0,
- "award_shop" => 0
- ]
- ],
- 'profit' => [
- 'commission' => [
- 'amount' => 0
- ],
- 'team-dividend' => [
- 'amount' => 0
- ],
- 'area-dividend' => [
- 'amount' => 0
- ],
- 'merchant-staff' => [
- 'amount' => 0
- ],
- 'merchant-center' => [
- 'amount' => 0
- ],
- 'single-return' => [
- 'amount' => 0
- ],
- 'full-return' => [
- 'is_open' => 0
- ],
- 'consume-return' => [
- 'is_open' => 0
- ]
- ]
- ];
- public static function relationSave($goodsId, $data, $operate)
- {
- if (!$goodsId) {
- return false;
- }
- if (!$data) {
- return false;
- }
- $saleModel = self::getModel($goodsId, $operate);
- //判断deleted
- if ($operate == 'deleted') {
- return $saleModel->delete();
- }
- foreach ($data['coupon_ids'] as $key_id => $id) {
- $data['coupon'][] = [
- 'id' => $id,
- 'name' => $data['coupon_names'][$key_id]
- ];
- }
- $data['goods_id'] = $goodsId;
- $data['plugins'] = serialize($data['plugins']);
- $data['profit'] = serialize($data['profit']);
- $data['coupon'] = serialize($data['coupon']);
- unset($data['coupon_ids']);
- unset($data['coupon_names']);
- $saleModel->fill($data);
- return $saleModel->save();
- }
- public static function getModel($goodsId, $operate)
- {
- $model = false;
- if ($operate != 'created') {
- $model = static::where(['goods_id' => $goodsId])->first();
- }
- !$model && $model = new static;
- return $model;
- }
- public function getDeductWidgets($widgets)
- {
- //积分
- $point = trim($widgets['sale']['point']);
- if (!$point) {
- $point = 0;
- }
- $widgets['sale']['point'] = $point .'%';
- $widgets['sale']['award_balance'] = $widgets['sale']['award_balance']?:0;
- $max_point_deduct = trim($widgets['sale']['max_point_deduct']);
- if (!$max_point_deduct) {
- $max_point_deduct = 0;
- }
- $widgets['sale']['max_point_deduct'] = $max_point_deduct .'%';
- $min_point_deduct = trim($widgets['sale']['min_point_deduct']);
- if (!$min_point_deduct) {
- $min_point_deduct = 0;
- }
- $widgets['sale']['min_point_deduct'] = $min_point_deduct .'%';
- //分享描述
- $widgets['share']['share_title'] = $widgets['share']['share_title'];
- $widgets['share']['share_thumb'] = $widgets['share']['share_thumb'];
- $widgets['share']['share_desc'] = $widgets['share']['share_desc'];
- //爱心值
- $exist_love = app('plugins')->isEnabled('love');
- if ($exist_love) {
- $widgets['love']['award'] = trim($widgets['love']['award']) ? trim($widgets['love']['award']) : 0;//爱心值奖励是否开启
- $widgets['love']['deduction'] = trim($widgets['love']['deduction']) ? trim($widgets['love']['deduction']) : 0;//爱心值抵扣是否开启
- $widgets['love']['parent_award'] = trim($widgets['love']['parent_award']) ? trim($widgets['love']['parent_award']) : 0;//爱心值上级奖励是否开启
- $widgets['love']['deduction_proportion'] = trim($widgets['love']['deduction_proportion']) ? trim($widgets['love']['deduction_proportion']) : 0;//爱心值最高抵扣
- $widgets['love']['award_proportion'] = trim($widgets['love']['award_proportion']) ? trim($widgets['love']['award_proportion']) : 0;//爱心值奖励
- if($widgets['love']['deduction_proportion'] == 0){
- $widgets['love']['deduction'] = 0;
- }
- if($widgets['love']['award_proportion'] == 0){
- $widgets['love']['award'] = 0;
- }
- $widgets['love']['parent_award_proportion'] = trim($widgets['love']['parent_award_proportion']) ? trim($widgets['love']['parent_award_proportion']) : 0;//爱心值上级第一级奖励
- $widgets['love']['second_award_proportion'] = trim($widgets['love']['second_award_proportion']) ? trim($widgets['love']['second_award_proportion']) : 0;//爱心值上级第二级奖励
- }
- //经销商
- $exist_team_dividend = app('plugins')->isEnabled('team-dividend');
- if ($exist_team_dividend) {
- $widgets['team_dividend']['is_dividend'] = trim($widgets['team_dividend']['is_dividend']) ? trim($widgets['team_dividend']['is_dividend']) : 0;
- if($widgets['team_dividend']['is_dividend'] == 1){
- $widgets['team_dividend']['has_dividend'] = 1;
- }else{
- $widgets['team_dividend']['has_dividend'] = 0;
- }
- $widgets['team_dividend']['has_dividend_rate'] = trim($widgets['team_dividend']['has_dividend_rate']) ? trim($widgets['team_dividend']['has_dividend_rate']) : 0;
- }
- //消费赠送
- $exist_single_return = app('plugins')->isEnabled('single-return');
- if ($exist_single_return) {
- $widgets['single_return']['return_rate'] = trim($widgets['single_return']['return_rate']) ? trim($widgets['single_return']['return_rate']) : 0;
- if( $widgets['single_return']['return_rate'] == 0){
- $widgets['single_return']['is_single_return'] = 0;
- }else{
- $widgets['single_return']['is_single_return'] = 1;
- }
- }
- return $widgets;
- }
- }
|