AddonsAlbumOrder.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace addons\Album\common\models;
  3. use Yii;
  4. use yii\db\Exception;
  5. /**
  6. * This is the model class for table "qimall_addons_album_order".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城ID
  10. * @property int $order_id 订单id
  11. * @property int $order_detail_id 订单详情id
  12. * @property int $user_id 用户id
  13. * @property int $album_id 画册id
  14. * @property int $album_page_id 画册页id
  15. * @property int $goods_id 商品id
  16. * @property int|null $order_count 订单数量
  17. * @property float $amount 支付金额
  18. * @property int $created_at 添加时间戳
  19. * @property string $date 日期
  20. */
  21. class AddonsAlbumOrder extends \common\models\base\BaseActiveRecord
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return '{{%addons_album_order}}';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['mall_id', 'order_id', 'order_detail_id', 'user_id', 'album_id', 'album_page_id', 'goods_id', 'order_count', 'created_at'], 'integer'],
  37. [['amount'], 'number'],
  38. [['date'], 'required'],
  39. [['date'], 'safe'],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'ID',
  49. 'mall_id' => '商城ID',
  50. 'order_id' => '订单id',
  51. 'order_detail_id' => '订单详情id',
  52. 'user_id' => '用户id',
  53. 'album_id' => '画册id',
  54. 'album_page_id' => '画册页id',
  55. 'goods_id' => '商品id',
  56. 'order_count' => '订单数量',
  57. 'amount' => '支付金额',
  58. 'created_at' => '添加时间戳',
  59. 'date' => '日期',
  60. ];
  61. }
  62. /**
  63. * @Author: ltm
  64. * @DateTime: 2022/2/15 0015 11:43
  65. * @Copyright: copyright (c) 2021 广东七件事集团
  66. * @param $data
  67. * @return string
  68. */
  69. public static function setData(array $params){
  70. try{
  71. $date = date("Y-m-d");
  72. $porson_num = AddonsAlbumOrder::findOne(['date'=> $date,'user_id' => $params['user_id'],'album_id' => $params['album_id']]);
  73. $model = new self();
  74. $model->created_at = time();
  75. $model->loadDefaultValues();
  76. $model->date = $date;
  77. $model->mall_id = $params['mall_id'];
  78. if(!$model->load($params,'') || !$model->save()){
  79. throw new Exception($model->getErrorMessage());
  80. }
  81. return $porson_num;
  82. }catch(\Exception $e){
  83. self::$static_error = $e->getMessage();
  84. return false;
  85. }
  86. }
  87. }