CommissionLog.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace addons\SalesCompany\common\models;
  3. use Yii;
  4. use common\models\base\BaseActiveRecord;
  5. use common\enums\StatusEnum;
  6. /**
  7. * This is the model class for table "{{%addons_sales_company_commission_log}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property string $source_table 来源表
  12. * @property int $source_table_id 来源表id
  13. * @property int $status 状态[-1:删除;0:禁用;1启用]
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 修改时间
  16. * @property float $total_money 总金额,单位:元
  17. * @property int $user_id 用户ID
  18. * @property float $money 实际到账金额,单位:元
  19. * @property float $rate 平台抽佣比例
  20. */
  21. class CommissionLog extends BaseActiveRecord
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return '{{%addons_sales_company_commission_log}}';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['mall_id', 'source_table_id', 'status', 'created_at', 'updated_at', 'user_id','is_frozen','agent_user_id','num'], 'integer'],
  37. [['total_money', 'money', 'rate','unit_goods_price'], 'number'],
  38. [['source_table','desc'], 'string', 'max' => 255],
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => 'ID',
  48. 'mall_id' => 'Mall ID',
  49. 'source_table' => 'Source Table',
  50. 'source_table_id' => 'Source Table ID',
  51. 'status' => 'Status',
  52. 'created_at' => 'Created At',
  53. 'updated_at' => 'Updated At',
  54. 'total_money' => 'Total Money',
  55. 'user_id' => 'User ID',
  56. 'money' => 'Money',
  57. 'rate' => 'Rate',
  58. 'is_frozen' => 'Is Frozen',
  59. 'agent_user_id' => 'agent_user_id',
  60. 'desc' => 'desc',
  61. 'unit_goods_price' => 'unit_goods_price',
  62. 'num' => 'num',
  63. ];
  64. }
  65. public static function setData(array $params)
  66. {
  67. try {
  68. if (!empty($params['id'])) {
  69. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  70. if (empty($model)) throw new \Exception('数据不存在或已删除');
  71. } else {
  72. $model = new self();
  73. $model->loadDefaultValues();
  74. }
  75. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  76. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  77. return $model;
  78. } catch (\Exception $e) {
  79. self::$static_error = $e->getMessage();
  80. return false;
  81. }
  82. }
  83. }