BossAchievementTeam.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace addons\BossAchievement\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "{{%addons_boss_achievement_team}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $user_id 用户ID
  12. * @property int $goods_id 购买过的商品id
  13. * @property float|null $finish_order_money 完成订单支付总金额,单位:元
  14. * @property int $month 月份,如:202207
  15. * @property int $is_settlement 是否已结算[0=否,1=是]
  16. * @property int $status 状态[-1:删除;0:禁用;1启用]
  17. * @property int $created_at
  18. * @property int $updated_at
  19. */
  20. class BossAchievementTeam extends \common\models\base\BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%addons_boss_achievement_team}}';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id', 'user_id', 'goods_id', 'month', 'is_settlement', 'status', 'created_at', 'updated_at'], 'integer'],
  36. [['finish_order_money'], 'number'],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'mall_id' => '商城ID',
  47. 'user_id' => '用户ID',
  48. 'goods_id' => '购买过的商品id',
  49. 'finish_order_money' => '完成订单支付总金额,单位:元',
  50. 'month' => '月份,如:202207',
  51. 'is_settlement' => '是否已结算[0=否,1=是]',
  52. 'status' => '状态[-1:删除;0:禁用;1启用]',
  53. 'created_at' => 'Created At',
  54. 'updated_at' => 'Updated At',
  55. ];
  56. }
  57. /**
  58. * 保存数据
  59. * @Author: lun
  60. * @DateTime: 2022/7/10 0010 16:24
  61. * @Copyright: copyright (c) 2021 广东七件事集团
  62. * @param $params
  63. * @return bool
  64. */
  65. public static function setData($params)
  66. {
  67. try {
  68. $month = date('Ym', time());
  69. $model = self::findOne(['mall_id' => $params['mall_id'], 'user_id' => $params['user_id'], 'goods_id' => $params['goods_id'], 'month' => $month, 'status' => StatusEnum::ENABLED]);
  70. if (empty($model)) {
  71. $model = new self();
  72. $model->mall_id = $params['mall_id'];
  73. $model->user_id = $params['user_id'];
  74. $model->goods_id = $params['goods_id'];
  75. $model->month = $month;
  76. $model->loadDefaultValues();
  77. }
  78. if (!empty($params['goods_price'])) $model->finish_order_money += $params['goods_price'];
  79. if (!$model->save()) throw new Exception($model->getErrorMessage());
  80. return true;
  81. } catch (\Exception $e) {
  82. self::setStaticError($e->getMessage());
  83. return false;
  84. }
  85. }
  86. }