StoreStatistics.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace addons\Store\common\models;
  3. use common\models\base\BaseActiveRecord;
  4. use Yii;
  5. /**
  6. * This is the model class for table "qimall_addons_store_statistics".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城id
  10. * @property int $store_id 门店id
  11. * @property string $date_time 月份
  12. * @property float $income_money 收入
  13. * @property int $created_at
  14. * @property int $updated_at
  15. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  16. */
  17. class StoreStatistics extends BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_store_statistics}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'store_id', 'created_at', 'updated_at', 'status'], 'integer'],
  33. [['income_money'], 'number'],
  34. [['date_time'], 'string', 'max' => 50],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'mall_id' => '商城id',
  45. 'store_id' => '门店id',
  46. 'date_time' => '月份',
  47. 'income_money' => '收入',
  48. 'created_at' => 'Created At',
  49. 'updated_at' => 'Updated At',
  50. 'status' => '状态[-1:删除;0:禁用;1启用]',
  51. ];
  52. }
  53. public static function updateIncomeMoney($store, $amount_received)
  54. {
  55. $date_time = date('Y-m', time());
  56. $aiyunuo_store_statistics = StoreStatistics::findOne(['mall_id' => $store['mall_id'], 'store_id' => $store['id'], 'date_time' => $date_time]);
  57. if (empty($aiyunuo_store_statistics)) {
  58. $aiyunuo_store_statistics = new StoreStatistics();
  59. $aiyunuo_store_statistics->loadDefaultValues();
  60. $aiyunuo_store_statistics->mall_id = $store['mall_id'];
  61. $aiyunuo_store_statistics->store_id = $store['id'];
  62. $aiyunuo_store_statistics->date_time = $date_time;
  63. }
  64. $aiyunuo_store_statistics->income_money += $amount_received;
  65. $aiyunuo_store_statistics->save();
  66. }
  67. }