BlindBoxUser.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace addons\BlindBox\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use common\models\common\Addons;
  6. use common\models\mall\MallAddons;
  7. use Yii;
  8. /**
  9. * This is the model class for table "qimall_addons_blind_box_user".
  10. *
  11. * @property int $id
  12. * @property int $mall_id 商城id
  13. * @property int $user_id 会员id
  14. * @property float $frozen_commission 冻结佣金
  15. * @property float $total_commission 总佣金(已结算)
  16. * @property float $total_pay_money 总消费金额
  17. * @property float $remaining_pay_money 剩余消费金额
  18. * @property int $status 状态[-1:删除;0:禁用;1启用]
  19. * @property int $created_at
  20. * @property int $updated_at
  21. */
  22. class BlindBoxUser extends BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_blind_box_user}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'user_id', 'status', 'created_at', 'updated_at'], 'integer'],
  38. [['frozen_commission', 'total_commission','total_pay_money','remaining_pay_money'], 'number'],
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => 'ID',
  48. 'mall_id' => '商城id',
  49. 'user_id' => '会员id',
  50. 'frozen_commission' => '冻结佣金',
  51. 'total_commission' => '总佣金(已结算)',
  52. 'total_pay_money' => '总消费金额',
  53. 'remaining_pay_money' => '剩余消费金额',
  54. 'status' => '状态[-1:删除;0:禁用;1启用]',
  55. 'created_at' => 'Created At',
  56. 'updated_at' => 'Updated At',
  57. ];
  58. }
  59. public static function setData(array $params)
  60. {
  61. try {
  62. $model = BlindBoxUser::findOne(['user_id' => $params['user_id'], 'mall_id' => $params['mall_id']]);
  63. if (empty($model)) {
  64. $model = new BlindBoxUser();
  65. $model->loadDefaultValues();
  66. $model->user_id = $params['user_id'];
  67. $model->mall_id = $params['mall_id'];
  68. }
  69. if (!empty($params['order_bonus'])) $model->frozen_commission = bcadd($model->frozen_commission, $params['order_bonus'], 2);
  70. if (!empty($params['total_pay_money'])) $model->total_pay_money = bcadd($model->total_pay_money, $params['total_pay_money'], 2);
  71. if (!empty($params['remaining_pay_money'])) $model->remaining_pay_money = $params['remaining_pay_money'];
  72. $res = $model->save();
  73. if ($res == false) throw new \Exception($model->getErrorMessage());
  74. return $model;
  75. } catch (\Exception $e) {
  76. self::$static_error = $e->getMessage();
  77. return false;
  78. }
  79. }
  80. public static function getAddons(array $params){
  81. $addons_name = $params['addons_name'];
  82. $is_install = MallAddons::isInstall($params['mall_id'], $addons_name);
  83. if($is_install){
  84. $detail = Addons::getOne([['name' =>$addons_name], ['is_online' => 1]], true,);
  85. return [
  86. 'addons_name'=>$addons_name,
  87. 'title'=>$detail['title'],
  88. ];
  89. }
  90. return [];
  91. }
  92. }