StoreGoodsRanking.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_goods_ranking".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $store_id 门店id
  11. * @property int $goods_id 商品id
  12. * @property int $sales_money 销售额
  13. * @property int $status 状态[0禁用 1启用 -1删除]
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 修改时间
  16. */
  17. class StoreGoodsRanking extends BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_store_goods_ranking}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'store_id', 'goods_id', 'sales_money', 'status', 'created_at', 'updated_at'], 'integer'],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'mall_id' => 'Mall ID',
  43. 'store_id' => '门店id',
  44. 'goods_id' => '商品id',
  45. 'sales_money' => '销售额',
  46. 'status' => '状态[0禁用 1启用 -1删除]',
  47. 'created_at' => '创建时间',
  48. 'updated_at' => '修改时间',
  49. ];
  50. }
  51. public static function setData($params)
  52. {
  53. try {
  54. if (!empty($params['mall_id']) && !empty($params['store_id']) && !empty($params['goods_id'])) {
  55. $model = StoreGoodsRanking::findOne(['goods_id' => $params['goods_id'], 'store_id' => $params['store_id'], 'mall_id' => $params['mall_id']]);
  56. if (empty($model)) {
  57. $model = new StoreGoodsRanking();
  58. $model->loadDefaultValues();
  59. $model->mall_id = $params['mall_id'];
  60. $model->store_id = $params['store_id'];
  61. $model->goods_id = $params['goods_id'];
  62. }
  63. if (!empty($params['sales_money'])) $model->sales_money += $params['sales_money'];
  64. $res = $model->save();
  65. }
  66. return true;
  67. } catch (\Exception $e) {
  68. self::$static_error = $e->getMessage();
  69. return false;
  70. }
  71. }
  72. }