ActivityCutPriceOrder.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%activity_cut_price_order}}".
  13. *
  14. * @property integer $id
  15. * @property integer $store_id
  16. * @property integer $activity_id
  17. * @property integer $user_id
  18. * @property integer $saas_id
  19. * @property integer $activity_goods_id
  20. * @property integer $goods_id
  21. * @property integer $order_mch_list
  22. * @property integer $total_price
  23. * @property integer $pay_price
  24. * @property integer $min_price
  25. * @property integer $used_order_id
  26. * @property integer $buy
  27. * @property integer $end_time
  28. * @property integer $created_at
  29. * @property integer $is_delete
  30. * @property integer $updated_at
  31. * @property integer $is_platform
  32. */
  33. class ActivityCutPriceOrder extends \yii\db\ActiveRecord
  34. {
  35. /**
  36. * @inheritdoc
  37. */
  38. public static function tableName()
  39. {
  40. return '{{%activity_cut_price_order}}';
  41. }
  42. public function behaviors()
  43. {
  44. return [
  45. [
  46. 'class' => TimestampBehavior::class,
  47. ]
  48. ];
  49. }
  50. public static function getStatus($order) {
  51. $status = 0;
  52. if ($order['end_time'] > time()) {
  53. $status = 0;//进行中
  54. }
  55. if ($order['end_time'] < time()) {
  56. $status = 1; //已结束
  57. }
  58. if ($order['buy'] == 0 && $order['end_time'] < time() && $order['pay_price'] > $order['min_price']) {
  59. $status = 2;//已失败
  60. }
  61. if ($order['used_order_id']) {
  62. $order = Order::find()->select('is_pay')->where(['id' => $order['used_order_id']])->one();
  63. if($order['is_pay'] <= 0){
  64. $status = 10;//待付款
  65. }else{
  66. $status = 11;//已付款
  67. }
  68. }
  69. return $status;
  70. }
  71. public function beforeSave($insert)
  72. {
  73. if (parent::beforeSave($insert)) {
  74. if ($this->dirtyAttributes && $this->dirtyAttributes['used_order_id'] && $this->dirtyAttributes['used_order_id'] > 0) {
  75. $activity_goods = ActivityCutPriceGoods::findOne($this->activity_goods_id);
  76. $activity_goods->sale_num += 1;
  77. $activity_goods->save();
  78. }
  79. }
  80. return true;
  81. }
  82. }