| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use app\jobs\storeSync\DiyCommon;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * Class CloudInventoryGoodsBind
- * @package app\modules\models
- * @property integer $id
- * @property integer $store_id
- * @property integer $cloud_inventory_cat_id
- * @property integer $cloud_goods_id
- * @property integer $supplier_id
- * @property string $name
- * @property integer $status
- * @property integer $num
- * @property string $pic_url
- * @property string $price
- * @property string $original_price
- * @property string $attrs
- * @property integer $use_attr
- * @property string $platform_negotiated_price
- * @property integer $is_delete
- * @property integer $created_at
- * @property integer $updated_at
- */
- class CloudInventoryGoodsBind extends ActiveRecord
- {
- public function behaviors()
- {
- return [
- [
- // 自动更新创建和更新时间
- 'class' => TimestampBehavior::class,
- 'value' => time()
- ]
- ];
- }
- public static function tableName()
- {
- return '{{%cloud_inventory_goods_bind}}';
- }
- public function rules()
- {
- return [
- [['store_id', 'cloud_inventory_cat_id','cloud_goods_id',], 'required'],
- [['store_id', 'cloud_inventory_cat_id', 'cloud_goods_id', 'supplier_id', 'updated_at', 'is_delete', 'status', 'num', 'use_attr'], 'integer'],
- [['pic_url', 'pic_url', 'price', 'original_price', 'attrs', 'platform_negotiated_price'], 'string'],
- [['name'], 'string', 'max' => 255],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'store_id' => '商城id',
- 'parent_id' => '上级分类id',
- 'name' => '分类名称',
- 'pic_url' => '分类图片url',
- 'sort' => '排序,升序',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- 'is_delete' => 'Is Delete',
- 'is_show' => '是否显示'
- ];
- }
- public function goodsList($param)
- {
- if (empty($param['cat_id']) && !empty($param['parent_id'])){
- $catIds = CloudInventoryGoodsCat::find()->where(['parent_id' => $param['parent_id']])->select('id')->column();
- $catIds[] = $param['parent_id'];
- }elseif (!empty($param['cat_id'])){
- $catIds[] = $param['cat_id'];
- }
- $query = self::find()->where(['is_delete' => 0 ,'status'=> 1]);
- if (!empty($catIds)) {
- $query->andWhere(['cloud_inventory_cat_id' => $catIds]);
- }
- if ($param['name']) {
- $query->andWhere(['like', 'name', $param['name']]);
- }
- if ($param['store_id']) {
- $query->andWhere(['store_id'=> $param['store_id']]);
- }
- if ($param['id']) {
- $query->andWhere(['id'=> $param['id']]);
- }
- if ($param['cloud_goods_id']) {
- $query->andWhere(['cloud_goods_id'=> $param['cloud_goods_id']]);
- }
- $query->orderBy("id desc");
- $list = pagination_make($query);
- $saaUser = get_saas_user();
- foreach ($list['list'] as &$item){
- $item["level_infos"] = array();
- $item['attrs'] = get_attrs_level_price($item['attrs'], $saaUser['cloud_inventory_level']);
- $attrs = json_decode($item['attrs'],true);
- $item['cloud_inventory_level_price'] = $attrs[0]['cloud_inventory_level_price'];
- $item['price'] = $attrs[0]['cloud_inventory_level_price'];
- if($saaUser['cloud_inventory_level'] == 4){
- $item["level_infos"][0] = array("name"=>"店老板","price"=> $attrs[0]['cloud_inventory_level_price2']);
- $item["level_infos"][1] = array("name"=>"高级代理商","price"=>$attrs[0]['cloud_inventory_level_price3']);
- }
- if($saaUser['cloud_inventory_level'] == 3){
- $item["level_infos"][0] = array("name"=>"店老板","price"=> $attrs[0]['cloud_inventory_level_price2']);
- }
- $item['sold_num'] = \Yii::$app->db->createCommand("
- SELECT SUM(num)
- FROM cyy_cloud_inventory_order_detail
- WHERE goods_id = :goods_id
- ", [':goods_id' => $item['cloud_goods_id']])->queryScalar();
- }
- $list['count'] = $list['totalCount'];
- $list['page'] = $list['pageNo'];
- unset($list['totalCount'],$list['pageNo']);
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $list
- ];
- }
- /**
- * @return int
- */
- public static function getStoreCatId($storeId,$cloudGoodsId)
- {
- $cloudInventoryGoodsBind = self::findOne(['store_id' => $storeId , 'cloud_goods_id' => $cloudGoodsId ]);
- if (!empty($cloudInventoryGoodsBind)){
- return $cloudInventoryGoodsBind['cloud_inventory_cat_id'];
- }
- return 0;
- }
- }
|