StoreClerkIncomeData.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace addons\Store\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use common\models\user\User;
  6. use Yii;
  7. /**
  8. * This is the model class for table "addons_store_clerk_income".
  9. *
  10. * @property int $id
  11. * @property int $mall_id
  12. * @property int $store_id 门店id
  13. * @property int $total_amount 核销总金额
  14. * @property int $total_count 核销次数
  15. * @property string $total_income 核销收入
  16. * @property string $status 状态[0禁用 1启用 -1删除]
  17. * @property int $created_at 创建时间
  18. * @property int $updated_at 修改时间
  19. */
  20. class StoreClerkIncomeData extends BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%addons_store_clerk_income_data}}';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id', 'store_id', 'total_count','created_at', 'updated_at','status'], 'integer'],
  36. [['total_amount','total_income'], 'number'],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'mall_id' => 'Mall ID',
  47. 'store_id' => '门店id',
  48. 'total_amount' => '总金额',
  49. 'total_income' => '总收益',
  50. 'total_count' => '总次数',
  51. 'status'=>'状态',
  52. 'created_at' => '创建时间',
  53. 'updated_at' => '修改时间',
  54. ];
  55. }
  56. public function getStore()
  57. {
  58. return $this->hasOne(Store::class, ['id' => 'store_id']);
  59. }
  60. public static function setData(array $params)
  61. {
  62. $t = Yii::$app->db->beginTransaction();
  63. try {
  64. if (!empty($params['id'])) {
  65. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  66. if (empty($model)) throw new \Exception('门店不存在或已删除');
  67. } else {
  68. $model = new self();
  69. $model->loadDefaultValues();
  70. }
  71. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  72. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  73. $t->commit();
  74. return $model;
  75. } catch (\Exception $e) {
  76. $t->rollBack();
  77. self::$static_error = $e->getMessage();
  78. return false;
  79. }
  80. }
  81. }