| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use app\modules\client\models\v1\common\CommonGoods;
- use app\utils\Notice\NoticeSend;
- use Yii;
- /**
- * This is the model class for table "{{%goods_lowering_price}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $user_id
- * @property integer $goods_id
- * @property integer $created_at
- * @property integer $is_delete
- * @property integer $type
- * @property integer $price
- */
- class GoodsLoweringPrice extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%goods_lowering_price}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['store_id', 'user_id', 'goods_id', 'created_at'], 'required'],
- [['store_id', 'user_id', 'saas_id','goods_id', 'created_at', 'is_delete', 'type'], 'integer'],
- [['price'], 'number'],
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'store_id' => 'Store ID',
- 'user_id' => 'User ID',
- 'saas_id' => 'Saas ID',
- 'goods_id' => 'Goods ID',
- 'created_at' => 'Addtime',
- 'is_delete' => 'Is Delete',
- 'price' => '期望价格',
- ];
- }
- /**
- * 模块名:sendMsg
- * 代码描述:发送降价通知
- * 作者:WPing丶
- * 创建时间:2024/03/09 16:47:50
- * @param int goods_id 商品id
- * @param int store_id 商城id
- * @param int price 商品修改后的价格
- */
- public static function sendMsg($goods_id, $store_id, $before_goods) {
- //debug_log('走到sendMsg');
- $goods = Goods::find()->where(['id' => $goods_id])->select('id,price,name,attr,is_level,mch_id')->asArray()->one();
- // $goods['diff_price'] = bcsub($before_price,$price,2);
- $list = self::find()->where(['goods_id' => $goods_id, 'is_delete' => 0, 'store_id' => $store_id])->asArray()->all();
- foreach($list as $item) {
- $user = User::findOne($item['user_id']);
- if(!$user) {
- continue;
- }
- $res = CommonGoods::getMemberPrice($goods,[],$user);
- $old_res = CommonGoods::getMemberPrice($before_goods,[],$user);
- $user_min_price = $res['min_member_price'] ? $res['min_member_price'] : $goods['price'];
- $old_user_min_price = $old_res['min_member_price'] ? $old_res['min_member_price'] : $before_goods['price'];
- // //debug_log($user);
- $goods['diff_price'] = bcsub($old_user_min_price,$user_min_price,2);
- $goods['user_min_price'] = $user_min_price;
- if($user_min_price < $old_user_min_price) {//判断修改后的价格是否达用户设定的期望价格
- NoticeSend::LoweringPrice($item['user_id'],$goods);
- $lowering = GoodsLoweringPrice::findOne(['user_id' => $item['user_id'], 'goods_id' => $goods_id, 'store_id' => $store_id, 'is_delete' => 0]);
- $lowering->price = $user_min_price;
- $lowering->save();
- }
- }
- }
- }
|