HappinessStoreStatistics.php 2.1 KB

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