| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace addons\ServeBonus\common\models;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_servebonus_order_log}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property int $buy_uid 购买者uid
- * @property int $level 出单用户等级
- * @property int $order_id 订单ID
- * @property int $order_no 订单编号
- * @property int $prize 出单奖励,单位:元
- * @property int $average_count 结算人数
- * @property int $date 出单日期,格式:20220124
- * @property int $is_settlement 是否已结算【0否,1是】
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class ServeBonusOrderLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_servebonus_order_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'order_id', 'order_detail_id', 'date','status', 'created_at', 'updated_at','order_type','goods_id','num'], 'integer'],
- [['order_no'], 'string'],
- [['money'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'order_id' => '订单ID',
- 'order_no' => '订单编号',
- 'money' => '订单金额,单位:元',
- 'order_detail_id' => '订单详情ID',
- 'date' => '出单日期,格式:20220124',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2022/1/25 0025 17:28
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return bool
- */
- public static function setData($params)
- {
- try {
- $model = self::findOne(['mall_id' => $params['mall_id'], 'order_id' => $params['order_id'], 'status' => StatusEnum::ENABLED]);
- if (!empty($model)) return true;
- $model = new self();
- $model->loadDefaultValues();
- if (!$model->load($params, '') || !$model->save()) {
- throw new Exception($model->getErrorMessage());
- }
- return true;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- /**
- * 获取当前期数指定等级业绩
- */
- public static function getTotalAmountsNum($mall_id,$level,$start_day,$end_day){
- if(empty($level)) return 0;
- $levelSetting = ServeBonusLevelSetting::find()->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED,'level'=>$level])->asArray()->one();
- if(empty($levelSetting) || empty($levelSetting['cloud_stock_achievement_prize'])) return 0;
- $list = self::find()->select('goods_id,num,money')
- ->where(['mall_id' => $mall_id])
- ->andFilterWhere(['between', 'date', $start_day, $end_day])
- ->asArray()
- ->all();
- $goods_ids = array_column($list,'goods_id');
- $goods_setting_list = ServeBonusCommissionItemSetting::find()
- ->where(['mall_id' => $mall_id,'item_id' => $goods_ids, 'is_enable' => StatusEnum::ENABLED])
- ->with(['detail'])
- ->indexBy('item_id')
- ->asArray()
- ->all();
- $total = 0;
- foreach($list as $item){
- $goods_setting = $goods_setting_list[$item['goods_id']];
- if(empty($goods_setting)) continue;
- if (!empty($goods_setting['is_alone']) && $goods_setting['is_alone'] == 1) {
- // 商品独立分佣配置
- $level_calculate = $goods_setting['detail'];
- $percent = $goods_setting['cloud_stock_achievement_percent'];
- } else {
- // 等级分佣配置
- $level_calculate[$level] = $levelSetting;
- $percent = $levelSetting['cloud_stock_achievement_percent'];
- }
- if(empty($percent)){
- $total += $level_calculate[$level]['cloud_stock_achievement_prize'] * $item['money'] / 100;
- }else{
- $total += $level_calculate[$level]['cloud_stock_achievement_prize'] * $item['num'];
- }
- }
- return $total;
- }
- }
|