| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace addons\Store\common\models;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_store_statistics".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $store_id 门店id
- * @property string $date_time 月份
- * @property float $income_money 收入
- * @property int $created_at
- * @property int $updated_at
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- */
- class StoreStatistics extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_statistics}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id', 'created_at', 'updated_at', 'status'], 'integer'],
- [['income_money'], 'number'],
- [['date_time'], 'string', 'max' => 50],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'store_id' => '门店id',
- 'date_time' => '月份',
- 'income_money' => '收入',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- ];
- }
- public static function updateIncomeMoney($store, $amount_received)
- {
- $date_time = date('Y-m', time());
- $aiyunuo_store_statistics = StoreStatistics::findOne(['mall_id' => $store['mall_id'], 'store_id' => $store['id'], 'date_time' => $date_time]);
- if (empty($aiyunuo_store_statistics)) {
- $aiyunuo_store_statistics = new StoreStatistics();
- $aiyunuo_store_statistics->loadDefaultValues();
- $aiyunuo_store_statistics->mall_id = $store['mall_id'];
- $aiyunuo_store_statistics->store_id = $store['id'];
- $aiyunuo_store_statistics->date_time = $date_time;
- }
- $aiyunuo_store_statistics->income_money += $amount_received;
- $aiyunuo_store_statistics->save();
- }
- }
|