GoodsLoweringPrice.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use app\modules\client\models\v1\common\CommonGoods;
  9. use app\utils\Notice\NoticeSend;
  10. use Yii;
  11. /**
  12. * This is the model class for table "{{%goods_lowering_price}}".
  13. *
  14. * @property integer $id
  15. * @property integer $store_id
  16. * @property integer $user_id
  17. * @property integer $goods_id
  18. * @property integer $created_at
  19. * @property integer $is_delete
  20. * @property integer $type
  21. * @property integer $price
  22. */
  23. class GoodsLoweringPrice extends \yii\db\ActiveRecord
  24. {
  25. /**
  26. * @inheritdoc
  27. */
  28. public static function tableName()
  29. {
  30. return '{{%goods_lowering_price}}';
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function rules()
  36. {
  37. return [
  38. [['store_id', 'user_id', 'goods_id', 'created_at'], 'required'],
  39. [['store_id', 'user_id', 'saas_id','goods_id', 'created_at', 'is_delete', 'type'], 'integer'],
  40. [['price'], 'number'],
  41. ];
  42. }
  43. /**
  44. * @inheritdoc
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'store_id' => 'Store ID',
  51. 'user_id' => 'User ID',
  52. 'saas_id' => 'Saas ID',
  53. 'goods_id' => 'Goods ID',
  54. 'created_at' => 'Addtime',
  55. 'is_delete' => 'Is Delete',
  56. 'price' => '期望价格',
  57. ];
  58. }
  59. /**
  60. * 模块名:sendMsg
  61. * 代码描述:发送降价通知
  62. * 作者:WPing丶
  63. * 创建时间:2024/03/09 16:47:50
  64. * @param int goods_id 商品id
  65. * @param int store_id 商城id
  66. * @param int price 商品修改后的价格
  67. */
  68. public static function sendMsg($goods_id, $store_id, $before_goods) {
  69. //debug_log('走到sendMsg');
  70. $goods = Goods::find()->where(['id' => $goods_id])->select('id,price,name,attr,is_level,mch_id')->asArray()->one();
  71. // $goods['diff_price'] = bcsub($before_price,$price,2);
  72. $list = self::find()->where(['goods_id' => $goods_id, 'is_delete' => 0, 'store_id' => $store_id])->asArray()->all();
  73. foreach($list as $item) {
  74. $user = User::findOne($item['user_id']);
  75. if(!$user) {
  76. continue;
  77. }
  78. $res = CommonGoods::getMemberPrice($goods,[],$user);
  79. $old_res = CommonGoods::getMemberPrice($before_goods,[],$user);
  80. $user_min_price = $res['min_member_price'] ? $res['min_member_price'] : $goods['price'];
  81. $old_user_min_price = $old_res['min_member_price'] ? $old_res['min_member_price'] : $before_goods['price'];
  82. // //debug_log($user);
  83. $goods['diff_price'] = bcsub($old_user_min_price,$user_min_price,2);
  84. $goods['user_min_price'] = $user_min_price;
  85. if($user_min_price < $old_user_min_price) {//判断修改后的价格是否达用户设定的期望价格
  86. NoticeSend::LoweringPrice($item['user_id'],$goods);
  87. $lowering = GoodsLoweringPrice::findOne(['user_id' => $item['user_id'], 'goods_id' => $goods_id, 'store_id' => $store_id, 'is_delete' => 0]);
  88. $lowering->price = $user_min_price;
  89. $lowering->save();
  90. }
  91. }
  92. }
  93. }