edit修改排序和日期
This commit is contained in:
parent
b598053673
commit
471b22e329
@ -1,67 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace app\components;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
|
||||
class Oss
|
||||
{
|
||||
|
||||
private $accessKeyId, $accessKeySecret, $bucket, $endpoint;
|
||||
|
||||
/**
|
||||
* Oss constructor.
|
||||
* @param $accessKeyId
|
||||
* @param $accessKeySecret
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->accessKeyId = 'LTAI5tShVduri66gPQj1arLQ';
|
||||
$this->accessKeySecret = 'R9pzKpWbfcudFO7VrWSz3BZst62ayX';
|
||||
$this->bucket = 'cxgyc';
|
||||
$this->endpoint = 'https://oss-cn-guangzhou.aliyuncs.com';
|
||||
|
||||
try {
|
||||
if (!isset($this->client)) {
|
||||
$this->client = $ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint, false);
|
||||
}
|
||||
} catch (OssException $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件到oss并删除本地文件
|
||||
* @param $file
|
||||
* @return bool|string
|
||||
*/
|
||||
public function upload($file)
|
||||
{
|
||||
$ext = explode('.', $file);
|
||||
$ext = end($ext);
|
||||
$date = date('Ymd');
|
||||
$file_name = md5(time() . uniqid());
|
||||
$oss_path = "upload/{$date}/{$file_name}.{$ext}";
|
||||
// $file = \Yii::$app->basePath . '/web' . $file;
|
||||
if (file_exists($file)) {
|
||||
try {
|
||||
$oss_client = $this->client->uploadFile($this->bucket, $oss_path, $file);
|
||||
} catch (OssException $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
if (isset($oss_client['info']['url'])) {
|
||||
// 自动删除本地的文件
|
||||
unlink($file);
|
||||
return $oss_client['info']['url'];
|
||||
} else {
|
||||
return $oss_client;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
namespace app\components;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
|
||||
class Oss
|
||||
{
|
||||
|
||||
private $accessKeyId, $accessKeySecret, $bucket, $endpoint;
|
||||
|
||||
/**
|
||||
* Oss constructor.
|
||||
* @param $accessKeyId
|
||||
* @param $accessKeySecret
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->accessKeyId = 'LTAI5tMaDbEbWyQWpwmxp24y';
|
||||
$this->accessKeySecret = '3bjqbBFC08YIub3c8ry9Elz05UF1J7';
|
||||
$this->bucket = 'cxgjyz';
|
||||
$this->endpoint = 'https://oss-cn-beijing.aliyuncs.com';
|
||||
|
||||
try {
|
||||
if (!isset($this->client)) {
|
||||
$this->client = $ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint, false);
|
||||
}
|
||||
} catch (OssException $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传文件到oss并删除本地文件
|
||||
* @param $file
|
||||
* @return bool|string
|
||||
*/
|
||||
public function upload($file)
|
||||
{
|
||||
$ext = explode('.', $file);
|
||||
$ext = end($ext);
|
||||
$date = date('Ymd');
|
||||
$file_name = md5(time() . uniqid());
|
||||
$oss_path = "upload/{$date}/{$file_name}.{$ext}";
|
||||
// $file = \Yii::$app->basePath . '/web' . $file;
|
||||
if (file_exists($file)) {
|
||||
try {
|
||||
$oss_client = $this->client->uploadFile($this->bucket, $oss_path, $file);
|
||||
} catch (OssException $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
if (isset($oss_client['info']['url'])) {
|
||||
// 自动删除本地的文件
|
||||
unlink($file);
|
||||
return $oss_client['info']['url'];
|
||||
} else {
|
||||
return $oss_client;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -17,6 +17,7 @@ use Yii;
|
||||
* @property int $is_delete 是否删除,0=否,1=是
|
||||
* @property int $deleted_at 删除时间
|
||||
* @property string $notice 包厢公告
|
||||
*
|
||||
*/
|
||||
class Box extends \yii\db\ActiveRecord
|
||||
{
|
||||
@ -35,7 +36,7 @@ class Box extends \yii\db\ActiveRecord
|
||||
{
|
||||
return [
|
||||
[['goods_id', 'bj_id', 'notice', 'status', 'created_at'], 'required'],
|
||||
[['goods_id', 'bj_id', 'status', 'created_at', 'updated_at', 'is_delete', 'deleted_at'], 'integer'],
|
||||
[['goods_id', 'bj_id', 'status', 'created_at', 'updated_at', 'is_delete', 'deleted_at','sort'], 'integer'],
|
||||
[['notice', 'cover_pic'], 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -1,104 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use Yii;
|
||||
use app\models\Model;
|
||||
|
||||
/**
|
||||
* This is the model class for table "{{%goods_hub}}".
|
||||
*
|
||||
* @property int $id ID
|
||||
* @property int $cx_mch_id 平台商户ID
|
||||
* @property string $name 商品名称
|
||||
* @property string|null $subtitle 副标题
|
||||
* @property float $original_price 原价
|
||||
* @property float $cost_price 成本价
|
||||
* @property string $detail 商品详情,图文
|
||||
* @property string $cover_pic 商品缩略图
|
||||
* @property string|null $pic_urls 商品轮播图
|
||||
* @property string|null $video_url 商品视频
|
||||
* @property string $unit 单位
|
||||
* @property int $created_at 添加时间
|
||||
* @property int $updated_at 更新时间
|
||||
* @property int $deleted_at 删除时间
|
||||
* @property int $is_delete 是否删除,0=否,1=是
|
||||
* @property int $type 商品类型:0=实体商品
|
||||
*/
|
||||
class GoodsHub extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%goods_hub}}';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['detail', 'pic_urls', 'name', 'subtitle', 'cover_pic', 'video_url', 'unit'], 'trim'],
|
||||
[['cx_mch_id', 'created_at', 'updated_at', 'deleted_at', 'is_delete', 'type'], 'integer'],
|
||||
[['name', 'detail', 'cover_pic'], 'required'],
|
||||
[['original_price', 'cost_price'], 'number'],
|
||||
[['detail', 'pic_urls'], 'string'],
|
||||
[['name', 'subtitle', 'cover_pic', 'video_url', 'unit'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'cx_mch_id' => '平台商户ID',
|
||||
'name' => '商品名称',
|
||||
'subtitle' => '副标题',
|
||||
'original_price' => '原价',
|
||||
'cost_price' => '成本价',
|
||||
'detail' => '商品详情,图文',
|
||||
'cover_pic' => '商品缩略图',
|
||||
'pic_urls' => '商品轮播图',
|
||||
'video_url' => '商品视频',
|
||||
'unit' => '单位',
|
||||
'created_at' => '添加时间',
|
||||
'updated_at' => '更新时间',
|
||||
'deleted_at' => '删除时间',
|
||||
'is_delete' => '是否删除,0=否,1=是',
|
||||
'type' => '商品类型:0=实体商品 ',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function beforeSave($insert) {
|
||||
if(parent::beforeSave($insert)){
|
||||
if($this->isNewRecord){
|
||||
$this->created_at = time();
|
||||
}
|
||||
$this->updated_at = time();
|
||||
if($this->is_delete == 1)
|
||||
$this->deleted_at = time();
|
||||
$this->htmlTagFilter();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function htmlTagFilter()
|
||||
{
|
||||
$this->name = Model::htmlTagFilter($this->name);
|
||||
$this->subtitle = Model::htmlTagFilter($this->subtitle);
|
||||
$this->detail = Model::htmlTagFilter($this->detail);
|
||||
$this->cover_pic = Model::htmlTagFilter($this->cover_pic);
|
||||
$this->video_url = Model::htmlTagFilter($this->video_url);
|
||||
$this->unit = Model::htmlTagFilter($this->unit);
|
||||
}
|
||||
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace app\models;
|
||||
|
||||
use Yii;
|
||||
use app\models\Model;
|
||||
|
||||
/**
|
||||
* This is the model class for table "{{%goods_hub}}".
|
||||
*
|
||||
* @property int $id ID
|
||||
* @property int $cx_mch_id 平台商户ID
|
||||
* @property string $name 商品名称
|
||||
* @property string|null $subtitle 副标题
|
||||
* @property float $original_price 原价
|
||||
* @property float $cost_price 成本价
|
||||
* @property string $detail 商品详情,图文
|
||||
* @property string $cover_pic 商品缩略图
|
||||
* @property string|null $pic_urls 商品轮播图
|
||||
* @property string|null $video_url 商品视频
|
||||
* @property string $unit 单位
|
||||
* @property int $created_at 添加时间
|
||||
* @property int $updated_at 更新时间
|
||||
* @property int $deleted_at 删除时间
|
||||
* @property int $is_delete 是否删除,0=否,1=是
|
||||
* @property int $type 商品类型:0=实体商品
|
||||
*/
|
||||
class GoodsHub extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return '{{%goods_hub}}';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['detail', 'pic_urls', 'name', 'subtitle', 'cover_pic', 'video_url', 'unit'], 'trim'],
|
||||
[['cx_mch_id', 'created_at', 'updated_at', 'deleted_at', 'is_delete', 'type'], 'integer'],
|
||||
[['name', 'detail', 'cover_pic'], 'required'],
|
||||
[['original_price', 'cost_price'], 'number'],
|
||||
[['detail', 'pic_urls'], 'string'],
|
||||
// [['name', 'subtitle', 'cover_pic', 'video_url', 'unit'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'cx_mch_id' => '平台商户ID',
|
||||
'name' => '商品名称',
|
||||
'subtitle' => '副标题',
|
||||
'original_price' => '原价',
|
||||
'cost_price' => '成本价',
|
||||
'detail' => '商品详情,图文',
|
||||
'cover_pic' => '商品缩略图',
|
||||
'pic_urls' => '商品轮播图',
|
||||
'video_url' => '商品视频',
|
||||
'unit' => '单位',
|
||||
'created_at' => '添加时间',
|
||||
'updated_at' => '更新时间',
|
||||
'deleted_at' => '删除时间',
|
||||
'is_delete' => '是否删除,0=否,1=是',
|
||||
'type' => '商品类型:0=实体商品 ',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function beforeSave($insert) {
|
||||
if(parent::beforeSave($insert)){
|
||||
if($this->isNewRecord){
|
||||
$this->created_at = time();
|
||||
}
|
||||
$this->updated_at = time();
|
||||
if($this->is_delete == 1)
|
||||
$this->deleted_at = time();
|
||||
$this->htmlTagFilter();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function htmlTagFilter()
|
||||
{
|
||||
$this->name = Model::htmlTagFilter($this->name);
|
||||
$this->subtitle = Model::htmlTagFilter($this->subtitle);
|
||||
$this->detail = Model::htmlTagFilter($this->detail);
|
||||
$this->cover_pic = Model::htmlTagFilter($this->cover_pic);
|
||||
$this->video_url = Model::htmlTagFilter($this->video_url);
|
||||
$this->unit = Model::htmlTagFilter($this->unit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,435 +1,435 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Any
|
||||
* @description KISS
|
||||
* @date 2021年10月5日
|
||||
* @version 1.0.0
|
||||
*
|
||||
* _____LOG_____
|
||||
*
|
||||
*/
|
||||
|
||||
namespace app\models\common;
|
||||
|
||||
use app\models\Goods;
|
||||
use app\models\GoodsAttr;
|
||||
use app\models\GoodsCat;
|
||||
use app\models\GoodsHub;
|
||||
use app\models\Cat;
|
||||
use app\models\Model;
|
||||
use app\components\SiteHelper;
|
||||
use app\components\SysConst;
|
||||
use app\components\Serializer;
|
||||
|
||||
|
||||
class CommonGoodsEditForm extends Model
|
||||
{
|
||||
public $name;
|
||||
public $subtitle;
|
||||
public $original_price;
|
||||
public $cost_price;
|
||||
public $detail = 0;
|
||||
public $cover_pic;
|
||||
public $pic_urls;
|
||||
public $video_url;
|
||||
public $unit;
|
||||
public $type;
|
||||
|
||||
public $price;
|
||||
public $use_attr;
|
||||
public $attr;
|
||||
public $goods_stock;
|
||||
public $virtual_sales;
|
||||
public $confine_count;
|
||||
public $freight_id;
|
||||
public $plugin_sign = 'goods';
|
||||
public $sort;
|
||||
public $cat_ids;
|
||||
public $goods_no;
|
||||
public $goods_weight;
|
||||
public $attrGroups;
|
||||
|
||||
|
||||
public $model;
|
||||
public $cx_mch_id;
|
||||
|
||||
public $newAttrs;
|
||||
|
||||
|
||||
public $banner_urls;
|
||||
public $video_banner_urls;
|
||||
|
||||
public $cat_id;
|
||||
public $cat1_id;
|
||||
public $cat2_id;
|
||||
public $cat3_id;
|
||||
public $cat4_id;
|
||||
public $date;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name', 'subtitle', 'detail', 'cover_pic', 'video_url', 'unit', 'plugin_sign', 'goods_no',], 'trim'],
|
||||
[['name', 'subtitle', 'detail', 'cover_pic', 'video_url', 'video_banner_urls', 'banner_urls', 'unit', 'plugin_sign', 'goods_no', 'date'], 'string'],
|
||||
[['original_price', 'cost_price', 'price', 'goods_weight'], 'number'],
|
||||
[['type', 'use_attr', 'goods_stock', 'virtual_sales', 'confine_count', 'freight_id', 'sort', 'cx_mch_id'], 'integer'],
|
||||
|
||||
[['cat_id', 'cat1_id', 'cat2_id', 'cat3_id', 'cat4_id',], 'integer'],
|
||||
|
||||
|
||||
[['pic_urls', 'cat_ids', 'model', 'attr', 'attrGroups'], 'safe'],
|
||||
[['cost_price', 'original_price', 'price'], 'number', 'min' => 0],
|
||||
[['cost_price', 'original_price', 'price'], 'number', 'max' => 9999999],
|
||||
[['sort', 'virtual_sales', 'freight_id'], 'default', 'value' => 100],
|
||||
[['confine_count', 'use_attr'], 'default', 'value' => 0],
|
||||
[['name', 'price', 'cover_pic', 'type', 'plugin_sign', 'banner_urls', 'model', 'cx_mch_id'], 'required'],
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'name' => '商品名称',
|
||||
'subtitle' => '副标题',
|
||||
'original_price' => '原价',
|
||||
'cost_price' => '成本价',
|
||||
'detail' => '商品详情,图文',
|
||||
'cover_pic' => '商品缩略图',
|
||||
'pic_urls' => '商品轮播图',
|
||||
'video_url' => '商品视频',
|
||||
'unit' => '单位',
|
||||
'type' => '商品类型:0=实体商品 ',
|
||||
'status' => '上架状态:0=下架,1=上架',
|
||||
'price' => '售价',
|
||||
'use_attr' => '是否使用规格:0=不使用,1=使用',
|
||||
'attr' => '商品规格',
|
||||
'goods_stock' => '商品库存',
|
||||
'virtual_sales' => '已出售量',
|
||||
'confine_count' => '购物数量限制,0=不限制',
|
||||
'freight_id' => '运费模板ID',
|
||||
'plugin_sign' => '商品标示用于区分商品属于什么模块',
|
||||
'sort' => '排序',
|
||||
];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
return $this->getModelError();
|
||||
}
|
||||
$t = \Yii::$app->db->beginTransaction();
|
||||
if ($this->model->isNewRecord) {
|
||||
$this->model->cx_mch_id = $this->cx_mch_id;
|
||||
$this->model->plugin_sign = $this->plugin_sign;
|
||||
}
|
||||
$this->model->price = $this->price;
|
||||
$this->model->goods_stock = empty($this->goods_stock) ? 9999 : $this->goods_stock; // 商品库存
|
||||
$this->model->virtual_sales = $this->virtual_sales;
|
||||
$this->model->confine_count = $this->confine_count;
|
||||
$this->model->freight_id = $this->freight_id;
|
||||
$this->model->sort = 100;
|
||||
$this->model->status = 1;
|
||||
// $this->handleAttrGroups();
|
||||
// $this->model->attr_groups = json_encode($this->attrGroups,JSON_UNESCAPED_UNICODE);
|
||||
$this->model->attr_groups = 1; //商品规格组 用不到看表 0 不需要规格组
|
||||
|
||||
$this->model->date = strtotime($this->date);
|
||||
|
||||
|
||||
//保存商品基础信息
|
||||
$res = $this->saveGoodsHub();
|
||||
|
||||
//保存商品基础信息
|
||||
$res1 = $this->saveGoodsCat();
|
||||
|
||||
|
||||
if ($res['code'] != 0 || $res1['code'] != 0) {
|
||||
$t->rollBack();
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
if (!$this->model->save()) {
|
||||
$t->rollBack();
|
||||
return $this->getModelError($this->model);
|
||||
}
|
||||
|
||||
$t->commit();
|
||||
return $this->apiReturnSuccess('保存成功');
|
||||
}
|
||||
|
||||
//扩展其他
|
||||
protected function saveExtra()
|
||||
{
|
||||
return $this->apiReturnSuccess();
|
||||
}
|
||||
|
||||
private function saveGoodsHub()
|
||||
{
|
||||
$goods_hub_id = $this->model->isNewRecord ? 0 : $this->model->goods_hub_id;
|
||||
$goods_hub = GoodsHub::findOne(['id' => $goods_hub_id, 'is_delete' => 0, 'cx_mch_id' => $this->cx_mch_id]);
|
||||
if ($goods_hub == null) {
|
||||
$goods_hub = new GoodsHub();
|
||||
$goods_hub->cx_mch_id = $this->cx_mch_id;
|
||||
}
|
||||
$goods_hub->name = $this->name;
|
||||
$goods_hub->subtitle = $this->subtitle;
|
||||
$goods_hub->original_price = $this->original_price ? $this->original_price : $this->price;
|
||||
$goods_hub->cost_price = $this->cost_price ? $this->cost_price : $this->price;
|
||||
$goods_hub->detail = $this->detail;
|
||||
$goods_hub->cover_pic = $this->cover_pic;
|
||||
|
||||
$goods_hub->banner_urls = $this->banner_urls;
|
||||
|
||||
|
||||
$video_banner_urls = is_string($this->video_banner_urls) ? $this->video_banner_urls : json_encode($this->video_banner_urls);
|
||||
$goods_hub->video_banner_urls = $video_banner_urls;
|
||||
|
||||
|
||||
$pic_urls = is_string($this->pic_urls) ? $this->pic_urls : json_encode($this->pic_urls);
|
||||
$goods_hub->pic_urls = $pic_urls;
|
||||
$video_urls = is_string($this->video_url) ? $this->video_url : json_encode($this->video_url);
|
||||
|
||||
|
||||
$goods_hub->video_url = $video_urls;
|
||||
$goods_hub->unit = $this->unit;
|
||||
$goods_hub->type = $this->type;
|
||||
if (!$goods_hub->save()) {
|
||||
return $this->getModelError($goods_hub);
|
||||
}
|
||||
$this->model->goods_hub_id = $goods_hub->id;
|
||||
return $this->apiReturnSuccess();
|
||||
}
|
||||
|
||||
//保存商品规格
|
||||
private function saveGoodsAttr()
|
||||
{
|
||||
if ((int)$this->use_attr === 0) {
|
||||
$this->model->use_attr = 0;
|
||||
// 未使用规格就添加默认规格
|
||||
$res = $this->setDefaultAttr();
|
||||
if ($res['code'] != 0)
|
||||
return $res;
|
||||
$attrPicList = [];
|
||||
} else {
|
||||
$this->handleAttr();
|
||||
// 多规格数据处理
|
||||
$this->newAttrs = $this->attr;
|
||||
$attrPicList = array_column($this->attrGroups[0]['attr_list'], 'cover_pic', 'attr_id');
|
||||
}
|
||||
|
||||
$oldAttr = GoodsAttr::find()
|
||||
->where(['is_delete' => 0, 'goods_id' => $this->model->id])
|
||||
->select('id')
|
||||
->asArray()
|
||||
->all();
|
||||
|
||||
// 是否为新增
|
||||
if (!$this->model->isNewRecord) {
|
||||
GoodsAttr::updateAll(['is_delete' => 1,], ['goods_id' => $this->model->id, 'is_delete' => 0]);
|
||||
}
|
||||
|
||||
// 旧规格ID
|
||||
$oldAttrIds = [];
|
||||
$newAttrIds = [];
|
||||
foreach ($oldAttr as $oldItem) {
|
||||
$oldAttrIds[] = $oldItem['id'];
|
||||
}
|
||||
|
||||
$goodsStock = 0;
|
||||
foreach ($this->newAttrs as $newAttr) {
|
||||
$goodsStock += $newAttr['stock'];
|
||||
|
||||
// 记录规格ID数组
|
||||
$signIds = '';
|
||||
foreach ($newAttr['attr_list'] as $aLItem) {
|
||||
$signIds .= $signIds ? ':' . (int)$aLItem['attr_id'] : (int)$aLItem['attr_id'];
|
||||
}
|
||||
|
||||
// TODO 待修改
|
||||
// 判断规格是需要新增还是更新
|
||||
$goodsAttr = null;
|
||||
if ($this->model->id) {
|
||||
$goodsAttr = GoodsAttr::findOne([
|
||||
'id' => isset($newAttr['id']) ? $newAttr['id'] : 0,
|
||||
'goods_id' => $this->model->id
|
||||
]);
|
||||
if ($goodsAttr == null && count($this->newAttrs) == 1) {
|
||||
$goodsAttr = GoodsAttr::findOne([
|
||||
'sign_id' => $signIds,
|
||||
'goods_id' => $this->model->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
if ($goodsAttr) {
|
||||
$goodsAttr->is_delete = 0;
|
||||
} else {
|
||||
$goodsAttr = new GoodsAttr();
|
||||
}
|
||||
if ($newAttr['stock'] > 9999999) {
|
||||
return $this->apiReturnError('商品总库存不能大于9999999');
|
||||
}
|
||||
$goodsAttr->goods_id = $this->model->id;
|
||||
$goodsAttr->sign_id = $signIds;
|
||||
$goodsAttr->stock = $newAttr['stock'];
|
||||
$goodsAttr->price = $newAttr['price'];
|
||||
$goodsAttr->serial_no = $newAttr['serial_no'];
|
||||
$goodsAttr->weight = $newAttr['weight'] ?: 0;
|
||||
$key = strstr($signIds, ':', true) ?: $signIds;
|
||||
$goodsAttr->cover_pic = !empty($newAttr['cover_pic']) ? $newAttr['cover_pic'] : $this->cover_pic;
|
||||
|
||||
$res = $goodsAttr->save();
|
||||
if (!$res) {
|
||||
return $this->getModelError($goodsAttr);
|
||||
}
|
||||
$newAttrIds[] = $goodsAttr->id;
|
||||
|
||||
}
|
||||
if ($goodsStock > 9999999) {
|
||||
return $this->apiReturnError('商品总库存不能大于9999999');
|
||||
}
|
||||
$this->model->goods_stock = $goodsStock;
|
||||
$res = $this->model->save();
|
||||
if (!$res) {
|
||||
return $this->getModelError($this->model);
|
||||
}
|
||||
return $this->apiReturnSuccess();
|
||||
}
|
||||
|
||||
private function handleAttrGroups()
|
||||
{
|
||||
$this->attrGroups = $this->addAttrGroupsId($this->attrGroups);
|
||||
}
|
||||
|
||||
private function handleAttr()
|
||||
{
|
||||
foreach ($this->attr as &$item) {
|
||||
foreach ($item['attr_list'] as &$alItem) {
|
||||
$alItem['attr_group_id'] = $this->newAttrGroupList[$alItem['attr_group_name']];
|
||||
$alItem['attr_id'] = $this->newAttrList[$alItem['attr_name']];
|
||||
}
|
||||
unset($alItem);
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
|
||||
private $newAttrGroupList = [];
|
||||
private $newAttrList = [];
|
||||
private $signArr = [];
|
||||
|
||||
private function addAttrGroupsId($list, &$id = 1)
|
||||
{
|
||||
$newId = 1;
|
||||
foreach ($list as $key => $item) {
|
||||
if (isset($item['attr_list'])) {
|
||||
$this->newAttrGroupList[$item['attr_group_name']] = $newId;
|
||||
$list[$key]['attr_group_id'] = $newId++;
|
||||
$newItemList = $this->addAttrGroupsId($item['attr_list'], $id);
|
||||
$list[$key]['attr_list'] = $newItemList;
|
||||
} else {
|
||||
if (isset($this->signArr[$item['attr_name']])) {
|
||||
$this->newAttrList[$item['attr_name']] = $this->signArr[$item['attr_name']];
|
||||
$list[$key]['attr_id'] = $this->signArr[$item['attr_name']];
|
||||
} else {
|
||||
$this->signArr[$item['attr_name']] = $id;
|
||||
$this->newAttrList[$item['attr_name']] = $id;
|
||||
$list[$key]['attr_id'] = $id++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加默认规格
|
||||
*/
|
||||
private function setDefaultAttr()
|
||||
{
|
||||
$attrList = [
|
||||
[
|
||||
|
||||
'attr_group_name' => '规格',
|
||||
'attr_group_id' => 1,
|
||||
'attr_id' => 1,
|
||||
'attr_name' => '默认',
|
||||
]
|
||||
];
|
||||
$count = 1;
|
||||
$attrGroups = [];
|
||||
foreach ($attrList as &$item) {
|
||||
$item['attr_group_id'] = $count;
|
||||
$count++;
|
||||
$item['attr_id'] = $count;
|
||||
$count++;
|
||||
$newItem = [
|
||||
'attr_group_id' => $item['attr_group_id'],
|
||||
'attr_group_name' => $item['attr_group_name'],
|
||||
'attr_list' => [
|
||||
[
|
||||
'attr_id' => $item['attr_id'],
|
||||
'attr_name' => $item['attr_name']
|
||||
]
|
||||
]
|
||||
];
|
||||
$attrGroups[] = $newItem;
|
||||
}
|
||||
unset($item);
|
||||
// 未使用规格 就添加一条默认规格
|
||||
$newAttrs = [
|
||||
[
|
||||
'attr_list' => $attrList,
|
||||
'stock' => $this->goods_stock,
|
||||
'price' => $this->price,
|
||||
'serial_no' => $this->goods_no ? $this->goods_no : '',
|
||||
'weight' => $this->goods_weight ? $this->goods_weight : 0,
|
||||
'cover_pic' => $this->cover_pic,
|
||||
]
|
||||
];
|
||||
|
||||
// 未使用规格情况下,要把上一次的规格ID 存回去,不然规格记录会重复添加
|
||||
if (count($this->attr) === 1 && isset($this->attr[0]['id'])) {
|
||||
$newAttrs[0]['id'] = $this->attr[0]['id'];
|
||||
}
|
||||
|
||||
$this->model->attr_groups = (new Serializer)->encode($attrGroups);
|
||||
$res = $this->model->save();
|
||||
if (!$res) {
|
||||
return $this->getModelError($this->model);
|
||||
}
|
||||
|
||||
$this->newAttrs = $newAttrs;
|
||||
return $this->apiReturnSuccess();
|
||||
}
|
||||
|
||||
|
||||
//保存商品分类
|
||||
protected function saveGoodsCat()
|
||||
{
|
||||
$type = Cat::TYPE_GOODS;
|
||||
$goods_hub_id = $this->model->goods_hub_id;
|
||||
|
||||
$goods_cat = GoodsCat::findOne(['goods_hub_id' => $goods_hub_id, 'is_delete' => 0]);
|
||||
|
||||
if ($goods_cat == null) {
|
||||
$goods_cat = new GoodsCat();
|
||||
}
|
||||
|
||||
$goods_cat->goods_hub_id = $goods_hub_id;
|
||||
|
||||
$goods_cat->cat_id = $this->cat_id;
|
||||
$goods_cat->cat1_id = $this->cat1_id;
|
||||
$goods_cat->cat2_id = $this->cat2_id;
|
||||
$goods_cat->cat3_id = $this->cat3_id;
|
||||
$goods_cat->cat4_id = $this->cat4_id;
|
||||
|
||||
$goods_cat->is_delete = 0;
|
||||
$res = $goods_cat->save();
|
||||
if (!$res) {
|
||||
return $this->getModelError($goods_cat);
|
||||
}
|
||||
|
||||
return $this->apiReturnSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Any
|
||||
* @description KISS
|
||||
* @date 2021年10月5日
|
||||
* @version 1.0.0
|
||||
*
|
||||
* _____LOG_____
|
||||
*
|
||||
*/
|
||||
|
||||
namespace app\models\common;
|
||||
|
||||
use app\models\Goods;
|
||||
use app\models\GoodsAttr;
|
||||
use app\models\GoodsCat;
|
||||
use app\models\GoodsHub;
|
||||
use app\models\Cat;
|
||||
use app\models\Model;
|
||||
use app\components\SiteHelper;
|
||||
use app\components\SysConst;
|
||||
use app\components\Serializer;
|
||||
|
||||
|
||||
class CommonGoodsEditForm extends Model
|
||||
{
|
||||
public $name;
|
||||
public $subtitle;
|
||||
public $original_price;
|
||||
public $cost_price;
|
||||
public $detail = 0;
|
||||
public $cover_pic;
|
||||
public $pic_urls;
|
||||
public $video_url;
|
||||
public $unit;
|
||||
public $type;
|
||||
|
||||
public $price;
|
||||
public $use_attr;
|
||||
public $attr;
|
||||
public $goods_stock;
|
||||
public $virtual_sales;
|
||||
public $confine_count;
|
||||
public $freight_id;
|
||||
public $plugin_sign = 'goods';
|
||||
public $sort;
|
||||
public $cat_ids;
|
||||
public $goods_no;
|
||||
public $goods_weight;
|
||||
public $attrGroups;
|
||||
|
||||
|
||||
public $model;
|
||||
public $cx_mch_id;
|
||||
|
||||
public $newAttrs;
|
||||
|
||||
|
||||
public $banner_urls;
|
||||
public $video_banner_urls;
|
||||
|
||||
public $cat_id;
|
||||
public $cat1_id;
|
||||
public $cat2_id;
|
||||
public $cat3_id;
|
||||
public $cat4_id;
|
||||
public $date;
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['name', 'subtitle', 'detail', 'cover_pic', 'video_url', 'unit', 'plugin_sign', 'goods_no',], 'trim'],
|
||||
[['name', 'subtitle', 'detail', 'cover_pic', 'video_url', 'video_banner_urls', 'banner_urls', 'unit', 'plugin_sign', 'goods_no', 'date'], 'string'],
|
||||
[['original_price', 'cost_price', 'price', 'goods_weight'], 'number'],
|
||||
[['type', 'use_attr', 'goods_stock', 'virtual_sales', 'confine_count', 'freight_id', 'sort', 'cx_mch_id'], 'integer'],
|
||||
|
||||
[['cat_id', 'cat1_id', 'cat2_id', 'cat3_id', 'cat4_id',], 'integer'],
|
||||
|
||||
|
||||
[['pic_urls', 'cat_ids', 'model', 'attr', 'attrGroups'], 'safe'],
|
||||
[['cost_price', 'original_price', 'price'], 'number', 'min' => 0],
|
||||
[['cost_price', 'original_price', 'price'], 'number', 'max' => 9999999],
|
||||
[['sort', 'virtual_sales', 'freight_id'], 'default', 'value' => 100],
|
||||
[['confine_count', 'use_attr'], 'default', 'value' => 0],
|
||||
[['name', 'price', 'cover_pic', 'type', 'plugin_sign', 'banner_urls', 'model', 'cx_mch_id'], 'required'],
|
||||
];
|
||||
}
|
||||
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'name' => '商品名称',
|
||||
'subtitle' => '副标题',
|
||||
'original_price' => '原价',
|
||||
'cost_price' => '成本价',
|
||||
'detail' => '商品详情,图文',
|
||||
'cover_pic' => '商品缩略图',
|
||||
'pic_urls' => '商品轮播图',
|
||||
'video_url' => '商品视频',
|
||||
'unit' => '单位',
|
||||
'type' => '商品类型:0=实体商品 ',
|
||||
'status' => '上架状态:0=下架,1=上架',
|
||||
'price' => '售价',
|
||||
'use_attr' => '是否使用规格:0=不使用,1=使用',
|
||||
'attr' => '商品规格',
|
||||
'goods_stock' => '商品库存',
|
||||
'virtual_sales' => '已出售量',
|
||||
'confine_count' => '购物数量限制,0=不限制',
|
||||
'freight_id' => '运费模板ID',
|
||||
'plugin_sign' => '商品标示用于区分商品属于什么模块',
|
||||
'sort' => '排序',
|
||||
];
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
return $this->getModelError();
|
||||
}
|
||||
$t = \Yii::$app->db->beginTransaction();
|
||||
if ($this->model->isNewRecord) {
|
||||
$this->model->cx_mch_id = $this->cx_mch_id;
|
||||
$this->model->plugin_sign = $this->plugin_sign;
|
||||
}
|
||||
$this->model->price = $this->price;
|
||||
$this->model->goods_stock = empty($this->goods_stock) ? 9999 : $this->goods_stock; // 商品库存
|
||||
$this->model->virtual_sales = $this->virtual_sales;
|
||||
$this->model->confine_count = $this->confine_count;
|
||||
$this->model->freight_id = $this->freight_id;
|
||||
$this->model->sort = $this->sort;
|
||||
$this->model->status = 1;
|
||||
// $this->handleAttrGroups();
|
||||
// $this->model->attr_groups = json_encode($this->attrGroups,JSON_UNESCAPED_UNICODE);
|
||||
$this->model->attr_groups = 1; //商品规格组 用不到看表 0 不需要规格组
|
||||
|
||||
$this->model->date = (int)strtotime($this->date."-01-01");
|
||||
|
||||
|
||||
//保存商品基础信息
|
||||
$res = $this->saveGoodsHub();
|
||||
|
||||
//保存商品基础信息
|
||||
$res1 = $this->saveGoodsCat();
|
||||
|
||||
|
||||
if ($res['code'] != 0 || $res1['code'] != 0) {
|
||||
$t->rollBack();
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
if (!$this->model->save()) {
|
||||
$t->rollBack();
|
||||
return $this->getModelError($this->model);
|
||||
}
|
||||
|
||||
$t->commit();
|
||||
return $this->apiReturnSuccess('保存成功');
|
||||
}
|
||||
|
||||
//扩展其他
|
||||
protected function saveExtra()
|
||||
{
|
||||
return $this->apiReturnSuccess();
|
||||
}
|
||||
|
||||
private function saveGoodsHub()
|
||||
{
|
||||
$goods_hub_id = $this->model->isNewRecord ? 0 : $this->model->goods_hub_id;
|
||||
$goods_hub = GoodsHub::findOne(['id' => $goods_hub_id, 'is_delete' => 0, 'cx_mch_id' => $this->cx_mch_id]);
|
||||
if ($goods_hub == null) {
|
||||
$goods_hub = new GoodsHub();
|
||||
$goods_hub->cx_mch_id = $this->cx_mch_id;
|
||||
}
|
||||
$goods_hub->name = $this->name;
|
||||
$goods_hub->subtitle = $this->subtitle;
|
||||
$goods_hub->original_price = $this->original_price ? $this->original_price : $this->price;
|
||||
$goods_hub->cost_price = $this->cost_price ? $this->cost_price : $this->price;
|
||||
$goods_hub->detail = $this->detail;
|
||||
$goods_hub->cover_pic = $this->cover_pic;
|
||||
|
||||
$goods_hub->banner_urls = $this->banner_urls;
|
||||
|
||||
|
||||
$video_banner_urls = is_string($this->video_banner_urls) ? $this->video_banner_urls : json_encode($this->video_banner_urls);
|
||||
$goods_hub->video_banner_urls = $video_banner_urls;
|
||||
|
||||
|
||||
$pic_urls = is_string($this->pic_urls) ? $this->pic_urls : json_encode($this->pic_urls);
|
||||
$goods_hub->pic_urls = $pic_urls;
|
||||
$video_urls = is_string($this->video_url) ? $this->video_url : json_encode($this->video_url);
|
||||
|
||||
|
||||
$goods_hub->video_url = $video_urls;
|
||||
$goods_hub->unit = $this->unit;
|
||||
$goods_hub->type = $this->type;
|
||||
if (!$goods_hub->save()) {
|
||||
return $this->getModelError($goods_hub);
|
||||
}
|
||||
$this->model->goods_hub_id = $goods_hub->id;
|
||||
return $this->apiReturnSuccess();
|
||||
}
|
||||
|
||||
//保存商品规格
|
||||
private function saveGoodsAttr()
|
||||
{
|
||||
if ((int)$this->use_attr === 0) {
|
||||
$this->model->use_attr = 0;
|
||||
// 未使用规格就添加默认规格
|
||||
$res = $this->setDefaultAttr();
|
||||
if ($res['code'] != 0)
|
||||
return $res;
|
||||
$attrPicList = [];
|
||||
} else {
|
||||
$this->handleAttr();
|
||||
// 多规格数据处理
|
||||
$this->newAttrs = $this->attr;
|
||||
$attrPicList = array_column($this->attrGroups[0]['attr_list'], 'cover_pic', 'attr_id');
|
||||
}
|
||||
|
||||
$oldAttr = GoodsAttr::find()
|
||||
->where(['is_delete' => 0, 'goods_id' => $this->model->id])
|
||||
->select('id')
|
||||
->asArray()
|
||||
->all();
|
||||
|
||||
// 是否为新增
|
||||
if (!$this->model->isNewRecord) {
|
||||
GoodsAttr::updateAll(['is_delete' => 1,], ['goods_id' => $this->model->id, 'is_delete' => 0]);
|
||||
}
|
||||
|
||||
// 旧规格ID
|
||||
$oldAttrIds = [];
|
||||
$newAttrIds = [];
|
||||
foreach ($oldAttr as $oldItem) {
|
||||
$oldAttrIds[] = $oldItem['id'];
|
||||
}
|
||||
|
||||
$goodsStock = 0;
|
||||
foreach ($this->newAttrs as $newAttr) {
|
||||
$goodsStock += $newAttr['stock'];
|
||||
|
||||
// 记录规格ID数组
|
||||
$signIds = '';
|
||||
foreach ($newAttr['attr_list'] as $aLItem) {
|
||||
$signIds .= $signIds ? ':' . (int)$aLItem['attr_id'] : (int)$aLItem['attr_id'];
|
||||
}
|
||||
|
||||
// TODO 待修改
|
||||
// 判断规格是需要新增还是更新
|
||||
$goodsAttr = null;
|
||||
if ($this->model->id) {
|
||||
$goodsAttr = GoodsAttr::findOne([
|
||||
'id' => isset($newAttr['id']) ? $newAttr['id'] : 0,
|
||||
'goods_id' => $this->model->id
|
||||
]);
|
||||
if ($goodsAttr == null && count($this->newAttrs) == 1) {
|
||||
$goodsAttr = GoodsAttr::findOne([
|
||||
'sign_id' => $signIds,
|
||||
'goods_id' => $this->model->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
if ($goodsAttr) {
|
||||
$goodsAttr->is_delete = 0;
|
||||
} else {
|
||||
$goodsAttr = new GoodsAttr();
|
||||
}
|
||||
if ($newAttr['stock'] > 9999999) {
|
||||
return $this->apiReturnError('商品总库存不能大于9999999');
|
||||
}
|
||||
$goodsAttr->goods_id = $this->model->id;
|
||||
$goodsAttr->sign_id = $signIds;
|
||||
$goodsAttr->stock = $newAttr['stock'];
|
||||
$goodsAttr->price = $newAttr['price'];
|
||||
$goodsAttr->serial_no = $newAttr['serial_no'];
|
||||
$goodsAttr->weight = $newAttr['weight'] ?: 0;
|
||||
$key = strstr($signIds, ':', true) ?: $signIds;
|
||||
$goodsAttr->cover_pic = !empty($newAttr['cover_pic']) ? $newAttr['cover_pic'] : $this->cover_pic;
|
||||
|
||||
$res = $goodsAttr->save();
|
||||
if (!$res) {
|
||||
return $this->getModelError($goodsAttr);
|
||||
}
|
||||
$newAttrIds[] = $goodsAttr->id;
|
||||
|
||||
}
|
||||
if ($goodsStock > 9999999) {
|
||||
return $this->apiReturnError('商品总库存不能大于9999999');
|
||||
}
|
||||
$this->model->goods_stock = $goodsStock;
|
||||
$res = $this->model->save();
|
||||
if (!$res) {
|
||||
return $this->getModelError($this->model);
|
||||
}
|
||||
return $this->apiReturnSuccess();
|
||||
}
|
||||
|
||||
private function handleAttrGroups()
|
||||
{
|
||||
$this->attrGroups = $this->addAttrGroupsId($this->attrGroups);
|
||||
}
|
||||
|
||||
private function handleAttr()
|
||||
{
|
||||
foreach ($this->attr as &$item) {
|
||||
foreach ($item['attr_list'] as &$alItem) {
|
||||
$alItem['attr_group_id'] = $this->newAttrGroupList[$alItem['attr_group_name']];
|
||||
$alItem['attr_id'] = $this->newAttrList[$alItem['attr_name']];
|
||||
}
|
||||
unset($alItem);
|
||||
}
|
||||
unset($item);
|
||||
}
|
||||
|
||||
private $newAttrGroupList = [];
|
||||
private $newAttrList = [];
|
||||
private $signArr = [];
|
||||
|
||||
private function addAttrGroupsId($list, &$id = 1)
|
||||
{
|
||||
$newId = 1;
|
||||
foreach ($list as $key => $item) {
|
||||
if (isset($item['attr_list'])) {
|
||||
$this->newAttrGroupList[$item['attr_group_name']] = $newId;
|
||||
$list[$key]['attr_group_id'] = $newId++;
|
||||
$newItemList = $this->addAttrGroupsId($item['attr_list'], $id);
|
||||
$list[$key]['attr_list'] = $newItemList;
|
||||
} else {
|
||||
if (isset($this->signArr[$item['attr_name']])) {
|
||||
$this->newAttrList[$item['attr_name']] = $this->signArr[$item['attr_name']];
|
||||
$list[$key]['attr_id'] = $this->signArr[$item['attr_name']];
|
||||
} else {
|
||||
$this->signArr[$item['attr_name']] = $id;
|
||||
$this->newAttrList[$item['attr_name']] = $id;
|
||||
$list[$key]['attr_id'] = $id++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加默认规格
|
||||
*/
|
||||
private function setDefaultAttr()
|
||||
{
|
||||
$attrList = [
|
||||
[
|
||||
|
||||
'attr_group_name' => '规格',
|
||||
'attr_group_id' => 1,
|
||||
'attr_id' => 1,
|
||||
'attr_name' => '默认',
|
||||
]
|
||||
];
|
||||
$count = 1;
|
||||
$attrGroups = [];
|
||||
foreach ($attrList as &$item) {
|
||||
$item['attr_group_id'] = $count;
|
||||
$count++;
|
||||
$item['attr_id'] = $count;
|
||||
$count++;
|
||||
$newItem = [
|
||||
'attr_group_id' => $item['attr_group_id'],
|
||||
'attr_group_name' => $item['attr_group_name'],
|
||||
'attr_list' => [
|
||||
[
|
||||
'attr_id' => $item['attr_id'],
|
||||
'attr_name' => $item['attr_name']
|
||||
]
|
||||
]
|
||||
];
|
||||
$attrGroups[] = $newItem;
|
||||
}
|
||||
unset($item);
|
||||
// 未使用规格 就添加一条默认规格
|
||||
$newAttrs = [
|
||||
[
|
||||
'attr_list' => $attrList,
|
||||
'stock' => $this->goods_stock,
|
||||
'price' => $this->price,
|
||||
'serial_no' => $this->goods_no ? $this->goods_no : '',
|
||||
'weight' => $this->goods_weight ? $this->goods_weight : 0,
|
||||
'cover_pic' => $this->cover_pic,
|
||||
]
|
||||
];
|
||||
|
||||
// 未使用规格情况下,要把上一次的规格ID 存回去,不然规格记录会重复添加
|
||||
if (count($this->attr) === 1 && isset($this->attr[0]['id'])) {
|
||||
$newAttrs[0]['id'] = $this->attr[0]['id'];
|
||||
}
|
||||
|
||||
$this->model->attr_groups = (new Serializer)->encode($attrGroups);
|
||||
$res = $this->model->save();
|
||||
if (!$res) {
|
||||
return $this->getModelError($this->model);
|
||||
}
|
||||
|
||||
$this->newAttrs = $newAttrs;
|
||||
return $this->apiReturnSuccess();
|
||||
}
|
||||
|
||||
|
||||
//保存商品分类
|
||||
protected function saveGoodsCat()
|
||||
{
|
||||
$type = Cat::TYPE_GOODS;
|
||||
$goods_hub_id = $this->model->goods_hub_id;
|
||||
|
||||
$goods_cat = GoodsCat::findOne(['goods_hub_id' => $goods_hub_id, 'is_delete' => 0]);
|
||||
|
||||
if ($goods_cat == null) {
|
||||
$goods_cat = new GoodsCat();
|
||||
}
|
||||
|
||||
$goods_cat->goods_hub_id = $goods_hub_id;
|
||||
|
||||
$goods_cat->cat_id = $this->cat_id;
|
||||
$goods_cat->cat1_id = $this->cat1_id;
|
||||
$goods_cat->cat2_id = $this->cat2_id;
|
||||
$goods_cat->cat3_id = $this->cat3_id;
|
||||
$goods_cat->cat4_id = $this->cat4_id;
|
||||
|
||||
$goods_cat->is_delete = 0;
|
||||
$res = $goods_cat->save();
|
||||
if (!$res) {
|
||||
return $this->getModelError($goods_cat);
|
||||
}
|
||||
|
||||
return $this->apiReturnSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,317 +1,317 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Any
|
||||
* @description KISS
|
||||
* @date 2021年10月5日
|
||||
* @version 1.0.0
|
||||
*
|
||||
* _____LOG_____
|
||||
*
|
||||
*/
|
||||
|
||||
namespace app\models\common;
|
||||
|
||||
use app\models\Cat1;
|
||||
use app\models\Cat2;
|
||||
use app\models\Cat3;
|
||||
use app\models\Cat4;
|
||||
use app\models\Goods;
|
||||
use app\models\GoodsAttr;
|
||||
use app\models\GoodsCat;
|
||||
use app\models\GoodsHub;
|
||||
use app\models\integral\mall\IntegralMallGoods;
|
||||
use app\models\Cat;
|
||||
use app\models\Model;
|
||||
use yii\data\Pagination;
|
||||
use app\components\SiteHelper;
|
||||
use app\components\SysConst;
|
||||
|
||||
|
||||
class CommonGoodsListForm extends Model
|
||||
{
|
||||
public $keywords;
|
||||
public $limit;
|
||||
public $page;
|
||||
|
||||
public $cat_id;
|
||||
public $cx_mch_id;
|
||||
public $status;
|
||||
public $goods_id;
|
||||
|
||||
public $start_time;
|
||||
public $end_time;
|
||||
|
||||
|
||||
public $plugin_sign;
|
||||
|
||||
private $fields;
|
||||
|
||||
|
||||
public $cat1_id;
|
||||
public $cat2_id;
|
||||
public $cat3_id;
|
||||
public $cat4_id;
|
||||
public $cat5_id;
|
||||
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['keywords', 'plugin_sign',], 'trim'],
|
||||
[['keywords', 'plugin_sign',], 'string'],
|
||||
[['limit', 'page', 'cx_mch_id', 'status', 'goods_id', 'cat_id'], 'integer'],
|
||||
[['cat_id', 'cat1_id', 'cat2_id', 'cat3_id', 'cat4_id'], 'integer'],
|
||||
[['page'], 'default', 'value' => 1],
|
||||
[['limit'], 'default', 'value' => 20],
|
||||
[['status'], 'in', 'range' => [0, 1, 2]],
|
||||
[['cx_mch_id'], 'required'],
|
||||
[['start_time', 'end_time',], 'safe'],
|
||||
[['goods_id'], 'required', 'on' => 'detail'],
|
||||
];
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
return $this->getModelError();
|
||||
}
|
||||
$cat_query = GoodsCat::find()
|
||||
->where([
|
||||
'is_delete' => 0,
|
||||
])
|
||||
->select('goods_hub_id,cat_id,cat1_id,cat2_id,cat3_id,cat4_id');
|
||||
$query = $this->getQuery($cat_query);
|
||||
$query = $query->where([
|
||||
'g.cx_mch_id' => $this->cx_mch_id,
|
||||
// 'g.is_delete' => 0,
|
||||
// 'gh.is_delete' => 0,
|
||||
// 'g.plugin_sign' => $this->plugin_sign,
|
||||
])
|
||||
->andFilterWhere([
|
||||
'OR',
|
||||
['LIKE', 'gh.name', $this->keywords],
|
||||
// ['LIKE', 'gh.subtitle', $this->keywords],
|
||||
])
|
||||
->andFilterWhere([
|
||||
'g.id' => $this->goods_id,
|
||||
'gc.cat_id' => $this->cat_id,
|
||||
'gc.cat1_id' => $this->cat1_id,
|
||||
'gc.cat2_id' => $this->cat2_id,
|
||||
'gc.cat3_id' => $this->cat3_id,
|
||||
'gc.cat4_id' => $this->cat4_id,
|
||||
]);
|
||||
if ($this->status == 2) {
|
||||
$query = $query->andWhere(['g.goods_stock' => 0]);//售罄
|
||||
} else {
|
||||
$query = $query->andFilterWhere(['g.status' => $this->status]);
|
||||
}
|
||||
$query = $this->switchTime($query);
|
||||
$query = $this->getFields($query);
|
||||
$count_query = clone $query;
|
||||
$count = $count_query->count();
|
||||
$pagination = new Pagination(['pageSize' => $this->limit, 'totalCount' => $count, 'page' => $this->page - 1]);
|
||||
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['g.sort' => SORT_ASC, 'g.created_at' => SORT_DESC])->asArray()->all();
|
||||
|
||||
|
||||
$list = $this->handleList($list);
|
||||
//是否已经全部加载
|
||||
$end_flag = $this->page > $pagination->pageCount ? true : false;
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => 'ok',
|
||||
'data' => $list,
|
||||
'count' => $count,
|
||||
'page_size' => $this->limit,
|
||||
'page_count' => $pagination->pageCount,
|
||||
'page_no' => $this->page,
|
||||
'end_flag' => $end_flag
|
||||
];
|
||||
}
|
||||
|
||||
protected function getQuery($cat_query)
|
||||
{
|
||||
$query = Goods::find()->alias('g')
|
||||
->leftJoin(['gh' => GoodsHub::tableName()], 'gh.id=g.goods_hub_id')
|
||||
->leftJoin(['gc' => $cat_query], 'gc.goods_hub_id=gh.id');
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function setFields($fields)
|
||||
{
|
||||
$this->fields = $fields;
|
||||
}
|
||||
|
||||
protected function getFields($query)
|
||||
{
|
||||
$fields = is_array($this->fields) ? implode(',', $this->fields) : $this->fields;
|
||||
return $query->select($fields);
|
||||
}
|
||||
|
||||
protected function handleList($list)
|
||||
{
|
||||
foreach ($list as $index => $item) {
|
||||
$item['status_cn'] = $item['status'] == Goods::STATUS_ONLINE ? '正常' : '隐藏';
|
||||
$item['created_at_cn'] = date('Y-m-d H:i:s', $item['created_at']);
|
||||
$item['date_at_cn'] = date('Y-m-d', $item['date']);
|
||||
|
||||
$item['cat_list'] = $this->getCatList($item['goods_hub_id']);
|
||||
|
||||
$item['cat1_list'] = $this->getCat1List($item['goods_hub_id']);
|
||||
$item['cat2_list'] = $this->getCat2List($item['goods_hub_id']);
|
||||
$item['cat3_list'] = $this->getCat3List($item['goods_hub_id']);
|
||||
$item['cat4_list'] = $this->getCat4List($item['goods_hub_id']);
|
||||
|
||||
|
||||
$item['cover_pic'] = SiteHelper::getFullUrl($item['cover_pic']);
|
||||
if ($this->scenario == 'detail') {
|
||||
$item['detail'] = SiteHelper::repairContent($item['detail']);
|
||||
$item['pic_urls'] = $this->fixPicUrls($item['pic_urls']);
|
||||
$item['video_url'] = SiteHelper::getFullUrl($item['video_url']);
|
||||
$item['goods_sales'] = $item['virtaul_sales'] + $item['sales'];
|
||||
$item['attr_groups'] = empty($item['attr_groups']) ? [] : json_decode($item['attr_groups'], true);
|
||||
$item['attr'] = $this->getAttr($item['id']);
|
||||
}
|
||||
$list[$index] = $item;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
protected function switchTime($query)
|
||||
{
|
||||
if (!empty($this->start_time)) {
|
||||
$query = $query->andWhere([
|
||||
'>',
|
||||
'g.created_at',
|
||||
strtotime($this->start_time)
|
||||
]);
|
||||
}
|
||||
if (!empty($this->end_time)) {
|
||||
$query = $query->andWhere([
|
||||
'<',
|
||||
'g.created_at',
|
||||
strtotime($this->end_time)
|
||||
]);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getCatList($goods_hub_id)
|
||||
{
|
||||
switch ($this->plugin_sign) {
|
||||
case SysConst::$cxPluginSceneMall:
|
||||
$type = Cat::TYPE_GOODS;
|
||||
break;
|
||||
case SysConst::$cxPluginSceneIntegralMall:
|
||||
$type = Cat::TYPE_INTEGRAL_GOODS;
|
||||
break;
|
||||
//@TODO 其他
|
||||
default:
|
||||
$type = Cat::TYPE_GOODS;
|
||||
}
|
||||
$list = GoodsCat::find()->alias('gc')
|
||||
->leftJoin(['c' => Cat::tableName()], 'c.id=gc.cat_id')
|
||||
->where([
|
||||
'gc.is_delete' => 0,
|
||||
'gc.goods_hub_id' => $goods_hub_id,
|
||||
'c.is_delete' => 0,
|
||||
'c.type' => $type,
|
||||
])
|
||||
->select('c.name,c.id as cat_id')->asArray()->all();
|
||||
return $list;
|
||||
}
|
||||
|
||||
protected function getCat1List($goods_hub_id)
|
||||
{
|
||||
$list = GoodsCat::find()->alias('gc')
|
||||
->leftJoin(['c' => Cat1::tableName()], 'c.id=gc.cat1_id')
|
||||
->where([
|
||||
'gc.is_delete' => 0,
|
||||
'gc.goods_hub_id' => $goods_hub_id,
|
||||
'c.is_delete' => 0,
|
||||
])
|
||||
->select('c.name,c.id as cat_id')->asArray()->all();
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
protected function getCat2List($goods_hub_id)
|
||||
{
|
||||
|
||||
$list = GoodsCat::find()->alias('gc')
|
||||
->leftJoin(['c' => Cat2::tableName()], 'c.id=gc.cat2_id')
|
||||
->where([
|
||||
'gc.is_delete' => 0,
|
||||
'gc.goods_hub_id' => $goods_hub_id,
|
||||
'c.is_delete' => 0,
|
||||
])
|
||||
->select('c.name,c.id as cat_id')->asArray()->all();
|
||||
return $list;
|
||||
}
|
||||
|
||||
protected function getCat3List($goods_hub_id)
|
||||
{
|
||||
|
||||
$list = GoodsCat::find()->alias('gc')
|
||||
->leftJoin(['c' => Cat3::tableName()], 'c.id=gc.cat3_id')
|
||||
->where([
|
||||
'gc.is_delete' => 0,
|
||||
'gc.goods_hub_id' => $goods_hub_id,
|
||||
'c.is_delete' => 0,
|
||||
])
|
||||
->select('c.name,c.id as cat_id')->asArray()->all();
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
protected function getCat4List($goods_hub_id)
|
||||
{
|
||||
|
||||
$list = GoodsCat::find()->alias('gc')
|
||||
->leftJoin(['c' => Cat4::tableName()], 'c.id=gc.cat4_id')
|
||||
->where([
|
||||
'gc.is_delete' => 0,
|
||||
'gc.goods_hub_id' => $goods_hub_id,
|
||||
'c.is_delete' => 0,
|
||||
])
|
||||
->select('c.name,c.id as cat_id')->asArray()->all();
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
protected function fixPicUrls($pic_urls)
|
||||
{
|
||||
$pic_urls = is_string($pic_urls) && !empty($pic_urls) ? json_decode($pic_urls, true) : $pic_urls;
|
||||
foreach ($pic_urls as $index => $item) {
|
||||
$item = SiteHelper::getFullUrl($item);
|
||||
$pic_urls[$index] = $item;
|
||||
}
|
||||
return $pic_urls;
|
||||
}
|
||||
|
||||
//获取商品规格
|
||||
private function getAttr($goods_id)
|
||||
{
|
||||
$attr = GoodsAttr::find()->alias('gr')
|
||||
->where([
|
||||
'gr.goods_id' => $goods_id,
|
||||
'gr.is_delete' => 0
|
||||
])
|
||||
->select('gr.id,gr.goods_id,gr.price,gr.sign_id,gr.stock,gr.serial_no,gr.weight,gr.cover_pic')
|
||||
->asArray()->all();
|
||||
foreach ($attr as $index => $item) {
|
||||
$item['cover_pic'] = SiteHelper::getFullUrl($item['cover_pic']);
|
||||
$attr[$index] = $item;
|
||||
}
|
||||
return $attr;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Any
|
||||
* @description KISS
|
||||
* @date 2021年10月5日
|
||||
* @version 1.0.0
|
||||
*
|
||||
* _____LOG_____
|
||||
*
|
||||
*/
|
||||
|
||||
namespace app\models\common;
|
||||
|
||||
use app\models\Cat1;
|
||||
use app\models\Cat2;
|
||||
use app\models\Cat3;
|
||||
use app\models\Cat4;
|
||||
use app\models\Goods;
|
||||
use app\models\GoodsAttr;
|
||||
use app\models\GoodsCat;
|
||||
use app\models\GoodsHub;
|
||||
use app\models\integral\mall\IntegralMallGoods;
|
||||
use app\models\Cat;
|
||||
use app\models\Model;
|
||||
use yii\data\Pagination;
|
||||
use app\components\SiteHelper;
|
||||
use app\components\SysConst;
|
||||
|
||||
|
||||
class CommonGoodsListForm extends Model
|
||||
{
|
||||
public $keywords;
|
||||
public $limit;
|
||||
public $page;
|
||||
|
||||
public $cat_id;
|
||||
public $cx_mch_id;
|
||||
public $status;
|
||||
public $goods_id;
|
||||
|
||||
public $start_time;
|
||||
public $end_time;
|
||||
|
||||
|
||||
public $plugin_sign;
|
||||
|
||||
private $fields;
|
||||
|
||||
|
||||
public $cat1_id;
|
||||
public $cat2_id;
|
||||
public $cat3_id;
|
||||
public $cat4_id;
|
||||
public $cat5_id;
|
||||
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['keywords', 'plugin_sign',], 'trim'],
|
||||
[['keywords', 'plugin_sign',], 'string'],
|
||||
[['limit', 'page', 'cx_mch_id', 'status', 'goods_id', 'cat_id'], 'integer'],
|
||||
[['cat_id', 'cat1_id', 'cat2_id', 'cat3_id', 'cat4_id'], 'integer'],
|
||||
[['page'], 'default', 'value' => 1],
|
||||
[['limit'], 'default', 'value' => 20],
|
||||
[['status'], 'in', 'range' => [0, 1, 2]],
|
||||
[['cx_mch_id'], 'required'],
|
||||
[['start_time', 'end_time',], 'safe'],
|
||||
[['goods_id'], 'required', 'on' => 'detail'],
|
||||
];
|
||||
}
|
||||
|
||||
public function search()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
return $this->getModelError();
|
||||
}
|
||||
$cat_query = GoodsCat::find()
|
||||
->where([
|
||||
'is_delete' => 0,
|
||||
])
|
||||
->select('goods_hub_id,cat_id,cat1_id,cat2_id,cat3_id,cat4_id');
|
||||
$query = $this->getQuery($cat_query);
|
||||
$query = $query->where([
|
||||
'g.cx_mch_id' => $this->cx_mch_id,
|
||||
'g.is_delete' => 0,
|
||||
// 'gh.is_delete' => 0,
|
||||
// 'g.plugin_sign' => $this->plugin_sign,
|
||||
])
|
||||
->andFilterWhere([
|
||||
'OR',
|
||||
['LIKE', 'gh.name', $this->keywords],
|
||||
// ['LIKE', 'gh.subtitle', $this->keywords],
|
||||
])
|
||||
->andFilterWhere([
|
||||
'g.id' => $this->goods_id,
|
||||
'gc.cat_id' => $this->cat_id,
|
||||
'gc.cat1_id' => $this->cat1_id,
|
||||
'gc.cat2_id' => $this->cat2_id,
|
||||
'gc.cat3_id' => $this->cat3_id,
|
||||
'gc.cat4_id' => $this->cat4_id,
|
||||
]);
|
||||
if ($this->status == 2) {
|
||||
$query = $query->andWhere(['g.goods_stock' => 0]);//售罄
|
||||
} else {
|
||||
$query = $query->andFilterWhere(['g.status' => $this->status]);
|
||||
}
|
||||
$query = $this->switchTime($query);
|
||||
$query = $this->getFields($query);
|
||||
$count_query = clone $query;
|
||||
$count = $count_query->count();
|
||||
$pagination = new Pagination(['pageSize' => $this->limit, 'totalCount' => $count, 'page' => $this->page - 1]);
|
||||
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['g.sort' => SORT_DESC, 'g.created_at' => SORT_DESC])->asArray()->all();
|
||||
|
||||
|
||||
$list = $this->handleList($list);
|
||||
//是否已经全部加载
|
||||
$end_flag = $this->page > $pagination->pageCount ? true : false;
|
||||
return [
|
||||
'code' => 0,
|
||||
'msg' => 'ok',
|
||||
'data' => $list,
|
||||
'count' => $count,
|
||||
'page_size' => $this->limit,
|
||||
'page_count' => $pagination->pageCount,
|
||||
'page_no' => $this->page,
|
||||
'end_flag' => $end_flag
|
||||
];
|
||||
}
|
||||
|
||||
protected function getQuery($cat_query)
|
||||
{
|
||||
$query = Goods::find()->alias('g')
|
||||
->leftJoin(['gh' => GoodsHub::tableName()], 'gh.id=g.goods_hub_id')
|
||||
->leftJoin(['gc' => $cat_query], 'gc.goods_hub_id=gh.id');
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function setFields($fields)
|
||||
{
|
||||
$this->fields = $fields;
|
||||
}
|
||||
|
||||
protected function getFields($query)
|
||||
{
|
||||
$fields = is_array($this->fields) ? implode(',', $this->fields) : $this->fields;
|
||||
return $query->select($fields);
|
||||
}
|
||||
|
||||
protected function handleList($list)
|
||||
{
|
||||
foreach ($list as $index => $item) {
|
||||
$item['status_cn'] = $item['status'] == Goods::STATUS_ONLINE ? '正常' : '隐藏';
|
||||
$item['created_at_cn'] = date('Y-m-d H:i:s', $item['created_at']);
|
||||
$item['date_at_cn'] = date('Y-m-d', $item['date']);
|
||||
|
||||
$item['cat_list'] = $this->getCatList($item['goods_hub_id']);
|
||||
|
||||
$item['cat1_list'] = $this->getCat1List($item['goods_hub_id']);
|
||||
$item['cat2_list'] = $this->getCat2List($item['goods_hub_id']);
|
||||
$item['cat3_list'] = $this->getCat3List($item['goods_hub_id']);
|
||||
$item['cat4_list'] = $this->getCat4List($item['goods_hub_id']);
|
||||
|
||||
|
||||
$item['cover_pic'] = SiteHelper::getFullUrl($item['cover_pic']);
|
||||
if ($this->scenario == 'detail') {
|
||||
$item['detail'] = SiteHelper::repairContent($item['detail']);
|
||||
$item['pic_urls'] = $this->fixPicUrls($item['pic_urls']);
|
||||
$item['video_url'] = SiteHelper::getFullUrl($item['video_url']);
|
||||
$item['goods_sales'] = $item['virtaul_sales'] + $item['sales'];
|
||||
$item['attr_groups'] = empty($item['attr_groups']) ? [] : json_decode($item['attr_groups'], true);
|
||||
$item['attr'] = $this->getAttr($item['id']);
|
||||
}
|
||||
$list[$index] = $item;
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
protected function switchTime($query)
|
||||
{
|
||||
if (!empty($this->start_time)) {
|
||||
$query = $query->andWhere([
|
||||
'>',
|
||||
'g.created_at',
|
||||
strtotime($this->start_time)
|
||||
]);
|
||||
}
|
||||
if (!empty($this->end_time)) {
|
||||
$query = $query->andWhere([
|
||||
'<',
|
||||
'g.created_at',
|
||||
strtotime($this->end_time)
|
||||
]);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function getCatList($goods_hub_id)
|
||||
{
|
||||
switch ($this->plugin_sign) {
|
||||
case SysConst::$cxPluginSceneMall:
|
||||
$type = Cat::TYPE_GOODS;
|
||||
break;
|
||||
case SysConst::$cxPluginSceneIntegralMall:
|
||||
$type = Cat::TYPE_INTEGRAL_GOODS;
|
||||
break;
|
||||
//@TODO 其他
|
||||
default:
|
||||
$type = Cat::TYPE_GOODS;
|
||||
}
|
||||
$list = GoodsCat::find()->alias('gc')
|
||||
->leftJoin(['c' => Cat::tableName()], 'c.id=gc.cat_id')
|
||||
->where([
|
||||
'gc.is_delete' => 0,
|
||||
'gc.goods_hub_id' => $goods_hub_id,
|
||||
'c.is_delete' => 0,
|
||||
'c.type' => $type,
|
||||
])
|
||||
->select('c.name,c.id as cat_id')->asArray()->all();
|
||||
return $list;
|
||||
}
|
||||
|
||||
protected function getCat1List($goods_hub_id)
|
||||
{
|
||||
$list = GoodsCat::find()->alias('gc')
|
||||
->leftJoin(['c' => Cat1::tableName()], 'c.id=gc.cat1_id')
|
||||
->where([
|
||||
'gc.is_delete' => 0,
|
||||
'gc.goods_hub_id' => $goods_hub_id,
|
||||
'c.is_delete' => 0,
|
||||
])
|
||||
->select('c.name,c.id as cat_id')->asArray()->all();
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
protected function getCat2List($goods_hub_id)
|
||||
{
|
||||
|
||||
$list = GoodsCat::find()->alias('gc')
|
||||
->leftJoin(['c' => Cat2::tableName()], 'c.id=gc.cat2_id')
|
||||
->where([
|
||||
'gc.is_delete' => 0,
|
||||
'gc.goods_hub_id' => $goods_hub_id,
|
||||
'c.is_delete' => 0,
|
||||
])
|
||||
->select('c.name,c.id as cat_id')->asArray()->all();
|
||||
return $list;
|
||||
}
|
||||
|
||||
protected function getCat3List($goods_hub_id)
|
||||
{
|
||||
|
||||
$list = GoodsCat::find()->alias('gc')
|
||||
->leftJoin(['c' => Cat3::tableName()], 'c.id=gc.cat3_id')
|
||||
->where([
|
||||
'gc.is_delete' => 0,
|
||||
'gc.goods_hub_id' => $goods_hub_id,
|
||||
'c.is_delete' => 0,
|
||||
])
|
||||
->select('c.name,c.id as cat_id')->asArray()->all();
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
protected function getCat4List($goods_hub_id)
|
||||
{
|
||||
|
||||
$list = GoodsCat::find()->alias('gc')
|
||||
->leftJoin(['c' => Cat4::tableName()], 'c.id=gc.cat4_id')
|
||||
->where([
|
||||
'gc.is_delete' => 0,
|
||||
'gc.goods_hub_id' => $goods_hub_id,
|
||||
'c.is_delete' => 0,
|
||||
])
|
||||
->select('c.name,c.id as cat_id')->asArray()->all();
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
protected function fixPicUrls($pic_urls)
|
||||
{
|
||||
$pic_urls = is_string($pic_urls) && !empty($pic_urls) ? json_decode($pic_urls, true) : $pic_urls;
|
||||
foreach ($pic_urls as $index => $item) {
|
||||
$item = SiteHelper::getFullUrl($item);
|
||||
$pic_urls[$index] = $item;
|
||||
}
|
||||
return $pic_urls;
|
||||
}
|
||||
|
||||
//获取商品规格
|
||||
private function getAttr($goods_id)
|
||||
{
|
||||
$attr = GoodsAttr::find()->alias('gr')
|
||||
->where([
|
||||
'gr.goods_id' => $goods_id,
|
||||
'gr.is_delete' => 0
|
||||
])
|
||||
->select('gr.id,gr.goods_id,gr.price,gr.sign_id,gr.stock,gr.serial_no,gr.weight,gr.cover_pic')
|
||||
->asArray()->all();
|
||||
foreach ($attr as $index => $item) {
|
||||
$item['cover_pic'] = SiteHelper::getFullUrl($item['cover_pic']);
|
||||
$attr[$index] = $item;
|
||||
}
|
||||
return $attr;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -194,7 +194,7 @@ class GoodsController extends Controller
|
||||
|
||||
$return_url = \Yii::$app->request->referrer;
|
||||
|
||||
$model->date = date('Y-m-d', $model->date);
|
||||
$model->date = date('Y', $model->date);
|
||||
|
||||
// var_dump($model->goodsHub->video_url);
|
||||
// var_dump($model->goodsHub->video_banner_urls);
|
||||
|
||||
@ -40,13 +40,14 @@ class BoxEditForm extends AdminModel
|
||||
public $updated_at;
|
||||
public $is_delete;
|
||||
public $deleted_at;
|
||||
public $sort;
|
||||
|
||||
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['status', 'created_at', 'updated_at', 'is_delete', 'deleted_at', 'goods_id', 'bj_id'], 'integer'],
|
||||
[['status', 'created_at', 'updated_at', 'is_delete', 'deleted_at', 'goods_id', 'bj_id','sort'], 'integer'],
|
||||
[['model'], 'safe'],
|
||||
[['notice', 'cover_pic'], 'string'],
|
||||
[['goods_id', 'bj_id', 'notice', 'cover_pic'], 'required'],
|
||||
@ -87,6 +88,7 @@ class BoxEditForm extends AdminModel
|
||||
$this->model->cover_pic = $this->cover_pic;
|
||||
$this->model->status = $this->status;
|
||||
$this->model->notice = $this->notice;
|
||||
$this->model->sort = $this->sort;
|
||||
|
||||
if (!$this->model->save()) {
|
||||
return $this->getModelError($this->model);
|
||||
|
||||
@ -56,7 +56,7 @@ class BoxListForm extends AdminModel
|
||||
->leftJoin(['goods' => Goods::tableName()], 'b.goods_id=goods.id')
|
||||
->leftJoin(['goodHub' => GoodsHub::tableName()], 'goods.goods_hub_id=goodHub.id')
|
||||
->leftJoin(['storeBj' => StoreBj::tableName()], 'b.bj_id=storeBj.id')
|
||||
->select('b.id,b.created_at,b.status,goodHub.name as goods_name,storeBj.name as bj_name')
|
||||
->select('b.id,b.created_at,b.status,goodHub.name as goods_name,storeBj.name as bj_name,b.sort')
|
||||
->where([
|
||||
'b.is_delete' => 0
|
||||
])
|
||||
@ -65,7 +65,7 @@ class BoxListForm extends AdminModel
|
||||
|
||||
$count = $query->count();
|
||||
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
|
||||
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['b.created_at' => SORT_DESC])->asArray()->all();
|
||||
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['b.sort'=>SORT_DESC,'b.id' => SORT_DESC])->asArray()->all();
|
||||
foreach ($list as $index => $item) {
|
||||
// $item['business'] = $item['begin_time'] . '-' . $item['end_time'];
|
||||
$item['created_at_cn'] = date("Y-m-d H:i", $item['created_at']);
|
||||
|
||||
@ -1,329 +1,344 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Any
|
||||
* @description KISS
|
||||
* @date 2021年10月5日
|
||||
* @version 1.0.0
|
||||
*
|
||||
* _____LOG_____
|
||||
*
|
||||
*/
|
||||
|
||||
use app\widgets\PickFile;
|
||||
use app\widgets\GoodsSku;
|
||||
use app\assets\UeditorAsset;
|
||||
|
||||
UeditorAsset::register($this);
|
||||
$this->title = $model->isNewRecord ? '添加冠军' : '编辑冠军';
|
||||
$this->params['breadcrumbs'][] = ['label' => '冠军', 'url' => [\Yii::$app->urlManager->createUrl(["admin/mall/goods/index"])]];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header"><?= $this->title ?></div>
|
||||
<div class="layui-card-body">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-md12">
|
||||
<div class="layui-form">
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">冠军名称</label>
|
||||
<div class="layui-input-inline">
|
||||
<input name="name" placeholder="请输入冠军名称" autocomplete="off"
|
||||
class="layui-input" value="<?= $model->goodsHub->name ?>" lay-verify="required">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<?= PickFile::widget([
|
||||
'accept' => 'images',
|
||||
'id' => 'cover_pic',
|
||||
'name' => 'cover_pic',
|
||||
'label' => '封面',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->cover_pic : '',
|
||||
'tip' => '图片大小750×750',
|
||||
'required' => true,
|
||||
'imageCompressEnable' => 1,
|
||||
'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">冠军级别</label>
|
||||
<div class="layui-input-block" style="width: 200px">
|
||||
<select name="cat_id">
|
||||
<option value=""></option>
|
||||
<?php foreach ($cat_list as $key => $val): ?>
|
||||
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">冠军分类</label>
|
||||
<div class="layui-input-block" style="width: 200px">
|
||||
<select name="cat1_id">
|
||||
<option value=""></option>
|
||||
<?php foreach ($cat_list1 as $key => $val): ?>
|
||||
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat1_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">签约价格</label>
|
||||
<div class="layui-input-block" style="width: 200px">
|
||||
<select name="cat2_id">
|
||||
<option value=""></option>
|
||||
<?php foreach ($cat_list2 as $key => $val): ?>
|
||||
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat2_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label ">多冠组合</label>
|
||||
<div class="layui-input-block" style="width: 200px">
|
||||
<select name="cat3_id">
|
||||
<option value=""></option>
|
||||
<?php foreach ($cat_list3 as $key => $val): ?>
|
||||
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat3_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">交付权益</label>
|
||||
<div class="layui-input-block" style="width: 200px">
|
||||
<select name="cat4_id">
|
||||
<option value=""></option>
|
||||
<?php foreach ($cat_list4 as $key => $val): ?>
|
||||
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat4_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">出生日期</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="date" name="date" placeholder="请输入出生日期" autocomplete="off"
|
||||
class="layui-input" value="<?= $model->date ?>" lay-verify="required">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">代表奖项</label>
|
||||
<div class="layui-input-inline">
|
||||
<input name="subtitle" placeholder="请输入代表奖项" autocomplete="off"
|
||||
class="layui-input" value="<?= $model->goodsHub->subtitle ?>"
|
||||
lay-verify="required">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">签约价格</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="number" name="price" placeholder="请输入售价" autocomplete="off"
|
||||
class="layui-input" value="<?= $model->price ?>" lay-verify="required">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<?= PickFile::widget([
|
||||
'multiple' => true,
|
||||
'accept' => 'images',
|
||||
'id' => 'pic_urls',
|
||||
'name' => 'pic_urls',
|
||||
'label' => '冠军轮播图(多张)',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->pic_urls : '',
|
||||
'tip' => '图片大小750×750',
|
||||
'required' => true,
|
||||
// 'imageCompressEnable' => 1,
|
||||
// 'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
|
||||
|
||||
<?= PickFile::widget([
|
||||
'accept' => 'images',
|
||||
'id' => 'banner_urls',
|
||||
'name' => 'banner_urls',
|
||||
'label' => '冠军详情图',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->banner_urls : '',
|
||||
// 'tip' => '图片大小750×750',
|
||||
'required' => true,
|
||||
'imageCompressEnable' => 1,
|
||||
'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
if (!empty($model->goodsHub->video_url)) {
|
||||
$json_de = json_decode($model->goodsHub->video_url, true);
|
||||
$temp_arr = [];
|
||||
foreach ($json_de as $key => $val) {
|
||||
$explode = explode('/', $val);
|
||||
$end = end($explode);
|
||||
//
|
||||
$temp_arr[] = [
|
||||
'name' => $end,
|
||||
'url' => $val,
|
||||
];
|
||||
}
|
||||
$model->goodsHub->video_url = json_encode($temp_arr, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<?= PickFile::widget([
|
||||
'accept' => 'file',
|
||||
'multiple' => true,
|
||||
'id' => 'video_url',
|
||||
'name' => 'video_url',
|
||||
'label' => '冠军视频',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->video_url : '',
|
||||
'tip' => '视频最大50M',
|
||||
'required' => false
|
||||
]) ?>
|
||||
|
||||
|
||||
<?= PickFile::widget([
|
||||
'multiple' => true,
|
||||
'accept' => 'images',
|
||||
'id' => 'video_banner_urls',
|
||||
'name' => 'video_banner_urls',
|
||||
'label' => '冠军视频封面图',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->video_banner_urls : '',
|
||||
'tip' => '图片大小750×750',
|
||||
'required' => true,
|
||||
// 'imageCompressEnable' => 1,
|
||||
// 'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<div class="">
|
||||
<button class="layui-btn" lay-submit="" lay-filter="layui-form-submit">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
<?php $this->beginBlock('js_script_wrap') ?>
|
||||
layui.config({
|
||||
base: '/statics/layuiadmin/' //静态资源所在路径
|
||||
}).extend({
|
||||
index: 'lib/index' //主入口模块
|
||||
}).use(['index', 'user'], function () {
|
||||
var $ = layui.$
|
||||
, setter = layui.setter
|
||||
, admin = layui.admin
|
||||
, form = layui.form
|
||||
, router = layui.router()
|
||||
, search = router.search;
|
||||
|
||||
form.render();
|
||||
//提交
|
||||
var submitLock = false;
|
||||
form.on('submit(layui-form-submit)', function (obj) {
|
||||
if (submitLock) {
|
||||
return false;
|
||||
}
|
||||
submitLock = true;
|
||||
//请求登入接口
|
||||
//console.log(obj)
|
||||
var url = '<?= \Yii::$app->urlManager->createUrl(["/admin/mall/goods/edit", 'id' => $model->id ? $model->id : 0]) ?>';
|
||||
var returnUrl = "<?= $return_url ?>";
|
||||
var data = obj.field;
|
||||
|
||||
var urls = []
|
||||
|
||||
data.video_banner_urls = JSON.stringify(_gallery_video_banner_urls);
|
||||
|
||||
|
||||
urls = window._filelist_video_url.map(function (val) {
|
||||
console.log(val)
|
||||
return val.url
|
||||
})
|
||||
|
||||
data.video_url = JSON.stringify(urls);
|
||||
data.pic_urls = JSON.stringify(_gallery_pic_urls);
|
||||
data._csrf = _csrf;
|
||||
|
||||
|
||||
console.log(data)
|
||||
|
||||
$.ajax(url, {
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: data,
|
||||
timeout: 10000,
|
||||
success: function (res) {
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, {
|
||||
offset: '15px'
|
||||
, icon: 1
|
||||
, time: 1000
|
||||
}, function () {
|
||||
if (returnUrl) {
|
||||
location.href = returnUrl;
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {
|
||||
offset: '15px'
|
||||
, icon: 2
|
||||
, time: 1000
|
||||
}, function () {
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function (xhr, type, err) {
|
||||
layer.msg(xhr.responseText, {
|
||||
offset: '15px'
|
||||
, icon: 2
|
||||
, time: 1000
|
||||
}, function () {
|
||||
});
|
||||
},
|
||||
complete: function () {
|
||||
submitLock = false;
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
<?php $this->endBlock(); ?>
|
||||
</script>
|
||||
<?php $this->registerJs($this->blocks['js_script_wrap'], \yii\web\View::POS_END); ?>
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Any
|
||||
* @description KISS
|
||||
* @date 2021年10月5日
|
||||
* @version 1.0.0
|
||||
*
|
||||
* _____LOG_____
|
||||
*
|
||||
*/
|
||||
|
||||
use app\widgets\PickFile;
|
||||
use app\widgets\GoodsSku;
|
||||
use app\assets\UeditorAsset;
|
||||
|
||||
UeditorAsset::register($this);
|
||||
$this->title = $model->isNewRecord ? '添加冠军' : '编辑冠军';
|
||||
$this->params['breadcrumbs'][] = ['label' => '冠军', 'url' => [\Yii::$app->urlManager->createUrl(["admin/mall/goods/index"])]];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="layui-fluid">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header"><?= $this->title ?></div>
|
||||
<div class="layui-card-body">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-md12">
|
||||
<div class="layui-form">
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">冠军名称</label>
|
||||
<div class="layui-input-inline">
|
||||
<input name="name" placeholder="请输入冠军名称" autocomplete="off"
|
||||
class="layui-input" value="<?= $model->goodsHub->name ?>" lay-verify="required">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<?= PickFile::widget([
|
||||
'accept' => 'images',
|
||||
'id' => 'cover_pic',
|
||||
'name' => 'cover_pic',
|
||||
'label' => '封面',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->cover_pic : '',
|
||||
'tip' => '图片大小750×750',
|
||||
'required' => true,
|
||||
'imageCompressEnable' => 1,
|
||||
'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">冠军级别</label>
|
||||
<div class="layui-input-block" style="width: 200px">
|
||||
<select name="cat_id">
|
||||
<option value=""></option>
|
||||
<?php foreach ($cat_list as $key => $val): ?>
|
||||
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">冠军分类</label>
|
||||
<div class="layui-input-block" style="width: 200px">
|
||||
<select name="cat1_id">
|
||||
<option value=""></option>
|
||||
<?php foreach ($cat_list1 as $key => $val): ?>
|
||||
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat1_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">签约价格</label>
|
||||
<div class="layui-input-block" style="width: 200px">
|
||||
<select name="cat2_id">
|
||||
<option value=""></option>
|
||||
<?php foreach ($cat_list2 as $key => $val): ?>
|
||||
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat2_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排序</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="number" name="sort" placeholder="请输入数字" autocomplete="off"
|
||||
class="layui-input" value="<?= $model->sort ? $model->sort : 100 ?>">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">降序,值越大排序越靠前</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">多冠组合</label>
|
||||
<div class="layui-input-block" style="width: 200px">
|
||||
<select name="cat3_id">
|
||||
<option value=""></option>
|
||||
<?php foreach ($cat_list3 as $key => $val): ?>
|
||||
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat3_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">交付权益</label>
|
||||
<div class="layui-input-block" style="width: 200px">
|
||||
<select name="cat4_id">
|
||||
<option value=""></option>
|
||||
<?php foreach ($cat_list4 as $key => $val): ?>
|
||||
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat4_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">出生日期</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="date" class="layui-input" id="test2" placeholder="yyyy">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">代表奖项</label>
|
||||
<div class="layui-input-inline">
|
||||
<input name="subtitle" placeholder="请输入代表奖项" autocomplete="off"
|
||||
class="layui-input" value="<?= $model->goodsHub->subtitle ?>"
|
||||
lay-verify="required">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">签约价格</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="number" name="price" placeholder="请输入售价" autocomplete="off"
|
||||
class="layui-input" value="<?= $model->price ?>" lay-verify="required">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux"></div>
|
||||
</div>
|
||||
|
||||
<?= PickFile::widget([
|
||||
'multiple' => true,
|
||||
'accept' => 'images',
|
||||
'id' => 'pic_urls',
|
||||
'name' => 'pic_urls',
|
||||
'label' => '冠军轮播图(多张)',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->pic_urls : '',
|
||||
'tip' => '图片大小750×750',
|
||||
'required' => true,
|
||||
// 'imageCompressEnable' => 1,
|
||||
// 'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
|
||||
|
||||
<?= PickFile::widget([
|
||||
'accept' => 'images',
|
||||
'id' => 'banner_urls',
|
||||
'name' => 'banner_urls',
|
||||
'label' => '冠军详情图',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->banner_urls : '',
|
||||
// 'tip' => '图片大小750×750',
|
||||
'required' => true,
|
||||
'imageCompressEnable' => 1,
|
||||
'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
if (!empty($model->goodsHub->video_url)) {
|
||||
$json_de = json_decode($model->goodsHub->video_url, true);
|
||||
$temp_arr = [];
|
||||
foreach ($json_de as $key => $val) {
|
||||
$explode = explode('/', $val);
|
||||
$end = end($explode);
|
||||
//
|
||||
$temp_arr[] = [
|
||||
'name' => $end,
|
||||
'url' => $val,
|
||||
];
|
||||
}
|
||||
$model->goodsHub->video_url = json_encode($temp_arr, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<?= PickFile::widget([
|
||||
'accept' => 'file',
|
||||
'multiple' => true,
|
||||
'id' => 'video_url',
|
||||
'name' => 'video_url',
|
||||
'label' => '冠军视频',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->video_url : '',
|
||||
'tip' => '视频最大50M',
|
||||
'required' => false
|
||||
]) ?>
|
||||
|
||||
|
||||
<?= PickFile::widget([
|
||||
'multiple' => true,
|
||||
'accept' => 'images',
|
||||
'id' => 'video_banner_urls',
|
||||
'name' => 'video_banner_urls',
|
||||
'label' => '冠军视频封面图',
|
||||
'value' => $model->goodsHub ? $model->goodsHub->video_banner_urls : '',
|
||||
'tip' => '图片大小750×750',
|
||||
'required' => true,
|
||||
// 'imageCompressEnable' => 1,
|
||||
// 'imageCompressBorder' => 750,
|
||||
]) ?>
|
||||
|
||||
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<div class="">
|
||||
<button class="layui-btn" lay-submit="" lay-filter="layui-form-submit">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
<?php $this->beginBlock('js_script_wrap') ?>
|
||||
layui.config({
|
||||
base: '/statics/layuiadmin/' //静态资源所在路径
|
||||
}).extend({
|
||||
index: 'lib/index' //主入口模块
|
||||
}).use(['index', 'user','laydate'], function () {
|
||||
var $ = layui.$
|
||||
, setter = layui.setter
|
||||
, admin = layui.admin
|
||||
, form = layui.form
|
||||
, router = layui.router()
|
||||
, laydate = layui.laydate
|
||||
, search = router.search;
|
||||
|
||||
form.render();
|
||||
//年选择器
|
||||
laydate.render({
|
||||
elem: '#test2'
|
||||
,type: 'year'
|
||||
,value: '<?= $model->date ?>'
|
||||
});
|
||||
//提交
|
||||
var submitLock = false;
|
||||
form.on('submit(layui-form-submit)', function (obj) {
|
||||
if (submitLock) {
|
||||
return false;
|
||||
}
|
||||
submitLock = true;
|
||||
//请求登入接口
|
||||
//console.log(obj)
|
||||
var url = '<?= \Yii::$app->urlManager->createUrl(["/admin/mall/goods/edit", 'id' => $model->id ? $model->id : 0]) ?>';
|
||||
var returnUrl = "<?= $return_url ?>";
|
||||
var data = obj.field;
|
||||
|
||||
var urls = []
|
||||
|
||||
data.video_banner_urls = JSON.stringify(_gallery_video_banner_urls);
|
||||
|
||||
|
||||
urls = window._filelist_video_url.map(function (val) {
|
||||
console.log(val)
|
||||
return val.url
|
||||
})
|
||||
|
||||
data.video_url = JSON.stringify(urls);
|
||||
data.pic_urls = JSON.stringify(_gallery_pic_urls);
|
||||
data._csrf = _csrf;
|
||||
|
||||
|
||||
console.log(data)
|
||||
|
||||
$.ajax(url, {
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: data,
|
||||
timeout: 10000,
|
||||
success: function (res) {
|
||||
if (res.code == 0) {
|
||||
layer.msg(res.msg, {
|
||||
offset: '15px'
|
||||
, icon: 1
|
||||
, time: 1000
|
||||
}, function () {
|
||||
if (returnUrl) {
|
||||
location.href = returnUrl;
|
||||
} else {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
layer.msg(res.msg, {
|
||||
offset: '15px'
|
||||
, icon: 2
|
||||
, time: 1000
|
||||
}, function () {
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function (xhr, type, err) {
|
||||
layer.msg(xhr.responseText, {
|
||||
offset: '15px'
|
||||
, icon: 2
|
||||
, time: 1000
|
||||
}, function () {
|
||||
});
|
||||
},
|
||||
complete: function () {
|
||||
submitLock = false;
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
<?php $this->endBlock(); ?>
|
||||
</script>
|
||||
<?php $this->registerJs($this->blocks['js_script_wrap'], \yii\web\View::POS_END); ?>
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -75,6 +75,13 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">案例排序</label>
|
||||
<div class="layui-input-block" style="width: 200px;">
|
||||
<input type="text" name="sort" class="layui-input" value="<?= $model->sort ?>">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="layui-form-item" style="display: block">
|
||||
<label class="layui-form-label required">案例状态</label>
|
||||
|
||||
@ -143,11 +143,11 @@ $user_type = \Yii::$app->request->get('user_type');
|
||||
, {field: 'id', title: 'ID', width: 80}
|
||||
, {field: 'goods_name', title: '冠军名称'}
|
||||
, {field: 'bj_name', title: '所属分类'}
|
||||
// , {field: 'money', title: '案例金额'}
|
||||
// , {field: 'device', title: '案例设备'}
|
||||
// , {field: 'business', title: '营业时间', width: 110}
|
||||
, {field: 'status', title: '状态', templet: '#statusTpl', width: 80}
|
||||
, {field: 'created_at_cn', title: '创建时间', width: 150}
|
||||
, {field: 'sort', title: '案例排序'}
|
||||
, {title: '操作', fixed: 'right', toolbar: '#rowBarTpl', width: 200}
|
||||
]
|
||||
]
|
||||
|
||||
@ -78,7 +78,7 @@ class GoodsController extends Controller
|
||||
$data = $form->search();
|
||||
|
||||
foreach ($data['data'] as $key => $value) {
|
||||
$data['data'][$key]['date'] = date('Y-m-d', $value['date']);
|
||||
$data['data'][$key]['date'] = date('Y', $value['date']);
|
||||
// $data['data'][$key]['video_url'] = SiteHelper::getFullUrl($value['video_url']);
|
||||
$data['data'][$key]['pic_arr'] = [];
|
||||
if ($value['pic_urls'] != null) {
|
||||
@ -141,7 +141,7 @@ class GoodsController extends Controller
|
||||
$data = $form->search();
|
||||
|
||||
foreach ($data['data'] as $key => $value) {
|
||||
$data['data'][$key]['date'] = date('Y-m-d', $value['date']);
|
||||
$data['data'][$key]['date'] = date('Y', $value['date']);
|
||||
$data['data'][$key]['pic_arr'] = [];
|
||||
if ($value['pic_urls'] != null) {
|
||||
$pic_arr = json_decode($value['pic_urls'], true);
|
||||
|
||||
@ -71,7 +71,7 @@ class BoxForm extends ApiModel
|
||||
|
||||
$count = $query->count();
|
||||
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]);
|
||||
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['b.created_at' => SORT_DESC])->asArray()->all();
|
||||
$list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['b.sort'=>SORT_DESC,'b.id' => SORT_DESC])->asArray()->all();
|
||||
foreach ($list as $index => $item) {
|
||||
// $item['business'] = $item['begin_time'] . '-' . $item['end_time'];
|
||||
$list[$index]['created_at_cn'] = date("Y-m-d H:i", $item['created_at']);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
BIN
vendor.rar
BIN
vendor.rar
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user