SettlementLog.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace addons\Store\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "{{%addons_store_settlement_log}}".
  8. *
  9. * @property int $id
  10. * @property int $order_id 订单id
  11. * @property int $store_id 门店id
  12. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  13. * @property int $created_at
  14. * @property int $updated_at
  15. * @property string $order_no 订单编号
  16. * @property int $is_settlement 是否已结算
  17. * @property int $settlement_at 结算时间
  18. */
  19. class SettlementLog extends BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%addons_store_settlement_log}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['order_id', 'store_id', 'status', 'created_at', 'updated_at', 'is_settlement', 'settlement_at'], 'integer'],
  35. [['order_no'], 'string', 'max' => 100],
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'order_id' => 'Order ID',
  46. 'store_id' => 'Store ID',
  47. 'status' => 'Status',
  48. 'created_at' => 'Created At',
  49. 'updated_at' => 'Updated At',
  50. 'order_no' => 'Order No',
  51. 'is_settlement' => 'Is Settlement',
  52. 'settlement_at' => 'Settlement At',
  53. ];
  54. }
  55. /**
  56. * 保存数据
  57. * @param array $params
  58. * @return bool
  59. */
  60. public static function setData(array $params)
  61. {
  62. try {
  63. if (!empty($params['id'])) {
  64. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  65. if (empty($model)) throw new \Exception('数据不存在或已删除');
  66. } else {
  67. $model = new self();
  68. $model->loadDefaultValues();
  69. }
  70. if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
  71. return $model;
  72. } catch (\Exception $e) {
  73. self::$static_error = $e->getMessage();
  74. return false;
  75. }
  76. }
  77. }