PkPerformanceOrder.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace addons\Pk\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "addons_pk_performance_order".
  6. *
  7. * @property int $id
  8. * @property int $order_id 订单ID
  9. * @property int $activity_id 活动ID
  10. * @property int $share_user_id 分享者用户ID
  11. * @property int $mall_id 商城ID
  12. * @property int $order_status 处理进度 【0未处理 1已处理 2无效】
  13. * @property int $source 来源【1自购 2直推 3分享】
  14. * @property int $status 状态[-1:删除;0:禁用;1启用]
  15. * @property int $created_at 创建时间
  16. * @property int $updated_at 更新时间
  17. */
  18. class PkPerformanceOrder extends \common\models\base\BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addons_pk_performance_order}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['order_id', 'activity_id', 'share_user_id', 'mall_id', 'order_status', 'source', 'status', 'created_at', 'updated_at'], 'integer'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'order_id' => '订单ID',
  44. 'activity_id' => '活动ID',
  45. 'share_user_id' => '分享者用户ID',
  46. 'mall_id' => '商城ID',
  47. 'order_status' => '处理进度 【0未处理 1已处理 2无效】',
  48. 'source' => '来源【1自购 2直推 3分享】',
  49. 'status' => '状态[-1:删除;0:禁用;1启用]',
  50. 'created_at' => '创建时间',
  51. 'updated_at' => '更新时间',
  52. ];
  53. }
  54. /**
  55. * 保存数据
  56. * @Author: ltm
  57. * @DateTime: 2022/6/8 0015 9:26
  58. * @Copyright: copyright (c) 2021
  59. * @param $mall_id
  60. * @param array $params
  61. * @return Rebate|bool
  62. */
  63. public static function setData(array $params){
  64. try{
  65. $mall_id = $params['mall_id'];
  66. if(!empty($params['id'])){
  67. $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $mall_id],['<>','status', StatusEnum::ENABLED]]);
  68. if(empty($model)) throw new \Exception('活动不存在或已删除');
  69. }else{
  70. $model = new self();
  71. $model->loadDefaultValues();
  72. $model->mall_id = $mall_id;
  73. }
  74. if(!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  75. return $model;
  76. }catch(\Exception $e){
  77. self::setStaticError($e->getMessage());
  78. return false;
  79. }
  80. }
  81. }