CloudInventoryGoodsBind.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use app\jobs\storeSync\DiyCommon;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * Class CloudInventoryGoodsBind
  13. * @package app\modules\models
  14. * @property integer $id
  15. * @property integer $store_id
  16. * @property integer $cloud_inventory_cat_id
  17. * @property integer $cloud_goods_id
  18. * @property integer $supplier_id
  19. * @property string $name
  20. * @property integer $status
  21. * @property integer $num
  22. * @property string $pic_url
  23. * @property string $price
  24. * @property string $original_price
  25. * @property string $attrs
  26. * @property integer $use_attr
  27. * @property string $platform_negotiated_price
  28. * @property integer $is_delete
  29. * @property integer $created_at
  30. * @property integer $updated_at
  31. */
  32. class CloudInventoryGoodsBind extends ActiveRecord
  33. {
  34. public function behaviors()
  35. {
  36. return [
  37. [
  38. // 自动更新创建和更新时间
  39. 'class' => TimestampBehavior::class,
  40. 'value' => time()
  41. ]
  42. ];
  43. }
  44. public static function tableName()
  45. {
  46. return '{{%cloud_inventory_goods_bind}}';
  47. }
  48. public function rules()
  49. {
  50. return [
  51. [['store_id', 'cloud_inventory_cat_id','cloud_goods_id',], 'required'],
  52. [['store_id', 'cloud_inventory_cat_id', 'cloud_goods_id', 'supplier_id', 'updated_at', 'is_delete', 'status', 'num', 'use_attr'], 'integer'],
  53. [['pic_url', 'pic_url', 'price', 'original_price', 'attrs', 'platform_negotiated_price'], 'string'],
  54. [['name'], 'string', 'max' => 255],
  55. ];
  56. }
  57. public function attributeLabels()
  58. {
  59. return [
  60. 'id' => 'ID',
  61. 'store_id' => '商城id',
  62. 'parent_id' => '上级分类id',
  63. 'name' => '分类名称',
  64. 'pic_url' => '分类图片url',
  65. 'sort' => '排序,升序',
  66. 'created_at' => '创建时间',
  67. 'updated_at' => '更新时间',
  68. 'is_delete' => 'Is Delete',
  69. 'is_show' => '是否显示'
  70. ];
  71. }
  72. public function goodsList($param)
  73. {
  74. if (empty($param['cat_id']) && !empty($param['parent_id'])){
  75. $catIds = CloudInventoryGoodsCat::find()->where(['parent_id' => $param['parent_id']])->select('id')->column();
  76. $catIds[] = $param['parent_id'];
  77. }elseif (!empty($param['cat_id'])){
  78. $catIds[] = $param['cat_id'];
  79. }
  80. $query = self::find()->where(['is_delete' => 0 ,'status'=> 1]);
  81. if (!empty($catIds)) {
  82. $query->andWhere(['cloud_inventory_cat_id' => $catIds]);
  83. }
  84. if ($param['name']) {
  85. $query->andWhere(['like', 'name', $param['name']]);
  86. }
  87. if ($param['store_id']) {
  88. $query->andWhere(['store_id'=> $param['store_id']]);
  89. }
  90. if ($param['id']) {
  91. $query->andWhere(['id'=> $param['id']]);
  92. }
  93. if ($param['cloud_goods_id']) {
  94. $query->andWhere(['cloud_goods_id'=> $param['cloud_goods_id']]);
  95. }
  96. $query->orderBy("id desc");
  97. $list = pagination_make($query);
  98. $saaUser = get_saas_user();
  99. foreach ($list['list'] as &$item){
  100. $item["level_infos"] = array();
  101. $item['attrs'] = get_attrs_level_price($item['attrs'], $saaUser['cloud_inventory_level']);
  102. $attrs = json_decode($item['attrs'],true);
  103. $item['cloud_inventory_level_price'] = $attrs[0]['cloud_inventory_level_price'];
  104. $item['price'] = $attrs[0]['cloud_inventory_level_price'];
  105. if($saaUser['cloud_inventory_level'] == 4){
  106. $item["level_infos"][0] = array("name"=>"店老板","price"=> $attrs[0]['cloud_inventory_level_price2']);
  107. $item["level_infos"][1] = array("name"=>"高级代理商","price"=>$attrs[0]['cloud_inventory_level_price3']);
  108. }
  109. if($saaUser['cloud_inventory_level'] == 3){
  110. $item["level_infos"][0] = array("name"=>"店老板","price"=> $attrs[0]['cloud_inventory_level_price2']);
  111. }
  112. $item['sold_num'] = \Yii::$app->db->createCommand("
  113. SELECT SUM(num)
  114. FROM cyy_cloud_inventory_order_detail
  115. WHERE goods_id = :goods_id
  116. ", [':goods_id' => $item['cloud_goods_id']])->queryScalar();
  117. }
  118. $list['count'] = $list['totalCount'];
  119. $list['page'] = $list['pageNo'];
  120. unset($list['totalCount'],$list['pageNo']);
  121. return [
  122. 'code' => 0,
  123. 'msg' => 'success',
  124. 'data' => $list
  125. ];
  126. }
  127. /**
  128. * @return int
  129. */
  130. public static function getStoreCatId($storeId,$cloudGoodsId)
  131. {
  132. $cloudInventoryGoodsBind = self::findOne(['store_id' => $storeId , 'cloud_goods_id' => $cloudGoodsId ]);
  133. if (!empty($cloudInventoryGoodsBind)){
  134. return $cloudInventoryGoodsBind['cloud_inventory_cat_id'];
  135. }
  136. return 0;
  137. }
  138. }