edit修改排序和日期

This commit is contained in:
admin 2023-12-09 16:31:30 +08:00
parent b598053673
commit 471b22e329
16 changed files with 2785 additions and 2759 deletions

View File

@ -1,67 +1,67 @@
<?php <?php
namespace app\components; namespace app\components;
use OSS\Core\OssException; use OSS\Core\OssException;
use OSS\OssClient; use OSS\OssClient;
class Oss class Oss
{ {
private $accessKeyId, $accessKeySecret, $bucket, $endpoint; private $accessKeyId, $accessKeySecret, $bucket, $endpoint;
/** /**
* Oss constructor. * Oss constructor.
* @param $accessKeyId * @param $accessKeyId
* @param $accessKeySecret * @param $accessKeySecret
* @throws \Exception * @throws \Exception
*/ */
public function __construct() public function __construct()
{ {
$this->accessKeyId = 'LTAI5tShVduri66gPQj1arLQ'; $this->accessKeyId = 'LTAI5tMaDbEbWyQWpwmxp24y';
$this->accessKeySecret = 'R9pzKpWbfcudFO7VrWSz3BZst62ayX'; $this->accessKeySecret = '3bjqbBFC08YIub3c8ry9Elz05UF1J7';
$this->bucket = 'cxgyc'; $this->bucket = 'cxgjyz';
$this->endpoint = 'https://oss-cn-guangzhou.aliyuncs.com'; $this->endpoint = 'https://oss-cn-beijing.aliyuncs.com';
try { try {
if (!isset($this->client)) { if (!isset($this->client)) {
$this->client = $ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint, false); $this->client = $ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint, false);
} }
} catch (OssException $e) { } catch (OssException $e) {
return $e->getMessage(); return $e->getMessage();
} }
} }
/** /**
* 上传文件到oss并删除本地文件 * 上传文件到oss并删除本地文件
* @param $file * @param $file
* @return bool|string * @return bool|string
*/ */
public function upload($file) public function upload($file)
{ {
$ext = explode('.', $file); $ext = explode('.', $file);
$ext = end($ext); $ext = end($ext);
$date = date('Ymd'); $date = date('Ymd');
$file_name = md5(time() . uniqid()); $file_name = md5(time() . uniqid());
$oss_path = "upload/{$date}/{$file_name}.{$ext}"; $oss_path = "upload/{$date}/{$file_name}.{$ext}";
// $file = \Yii::$app->basePath . '/web' . $file; // $file = \Yii::$app->basePath . '/web' . $file;
if (file_exists($file)) { if (file_exists($file)) {
try { try {
$oss_client = $this->client->uploadFile($this->bucket, $oss_path, $file); $oss_client = $this->client->uploadFile($this->bucket, $oss_path, $file);
} catch (OssException $e) { } catch (OssException $e) {
return $e->getMessage(); return $e->getMessage();
} }
if (isset($oss_client['info']['url'])) { if (isset($oss_client['info']['url'])) {
// 自动删除本地的文件 // 自动删除本地的文件
unlink($file); unlink($file);
return $oss_client['info']['url']; return $oss_client['info']['url'];
} else { } else {
return $oss_client; return $oss_client;
} }
} }
return false; return false;
} }
} }

View File

@ -17,6 +17,7 @@ use Yii;
* @property int $is_delete 是否删除0=1= * @property int $is_delete 是否删除0=1=
* @property int $deleted_at 删除时间 * @property int $deleted_at 删除时间
* @property string $notice 包厢公告 * @property string $notice 包厢公告
*
*/ */
class Box extends \yii\db\ActiveRecord class Box extends \yii\db\ActiveRecord
{ {
@ -35,7 +36,7 @@ class Box extends \yii\db\ActiveRecord
{ {
return [ return [
[['goods_id', 'bj_id', 'notice', 'status', 'created_at'], 'required'], [['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'], [['notice', 'cover_pic'], 'string'],
]; ];
} }

View File

@ -1,104 +1,104 @@
<?php <?php
namespace app\models; namespace app\models;
use Yii; use Yii;
use app\models\Model; use app\models\Model;
/** /**
* This is the model class for table "{{%goods_hub}}". * This is the model class for table "{{%goods_hub}}".
* *
* @property int $id ID * @property int $id ID
* @property int $cx_mch_id 平台商户ID * @property int $cx_mch_id 平台商户ID
* @property string $name 商品名称 * @property string $name 商品名称
* @property string|null $subtitle 副标题 * @property string|null $subtitle 副标题
* @property float $original_price 原价 * @property float $original_price 原价
* @property float $cost_price 成本价 * @property float $cost_price 成本价
* @property string $detail 商品详情,图文 * @property string $detail 商品详情,图文
* @property string $cover_pic 商品缩略图 * @property string $cover_pic 商品缩略图
* @property string|null $pic_urls 商品轮播图 * @property string|null $pic_urls 商品轮播图
* @property string|null $video_url 商品视频 * @property string|null $video_url 商品视频
* @property string $unit 单位 * @property string $unit 单位
* @property int $created_at 添加时间 * @property int $created_at 添加时间
* @property int $updated_at 更新时间 * @property int $updated_at 更新时间
* @property int $deleted_at 删除时间 * @property int $deleted_at 删除时间
* @property int $is_delete 是否删除0=1= * @property int $is_delete 是否删除0=1=
* @property int $type 商品类型0=实体商品 * @property int $type 商品类型0=实体商品
*/ */
class GoodsHub extends \yii\db\ActiveRecord class GoodsHub extends \yii\db\ActiveRecord
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function tableName() public static function tableName()
{ {
return '{{%goods_hub}}'; return '{{%goods_hub}}';
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function rules() public function rules()
{ {
return [ return [
[['detail', 'pic_urls', 'name', 'subtitle', 'cover_pic', 'video_url', 'unit'], 'trim'], [['detail', 'pic_urls', 'name', 'subtitle', 'cover_pic', 'video_url', 'unit'], 'trim'],
[['cx_mch_id', 'created_at', 'updated_at', 'deleted_at', 'is_delete', 'type'], 'integer'], [['cx_mch_id', 'created_at', 'updated_at', 'deleted_at', 'is_delete', 'type'], 'integer'],
[['name', 'detail', 'cover_pic'], 'required'], [['name', 'detail', 'cover_pic'], 'required'],
[['original_price', 'cost_price'], 'number'], [['original_price', 'cost_price'], 'number'],
[['detail', 'pic_urls'], 'string'], [['detail', 'pic_urls'], 'string'],
[['name', 'subtitle', 'cover_pic', 'video_url', 'unit'], 'string', 'max' => 255], // [['name', 'subtitle', 'cover_pic', 'video_url', 'unit'], 'string', 'max' => 255],
]; ];
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function attributeLabels() public function attributeLabels()
{ {
return [ return [
'id' => 'ID', 'id' => 'ID',
'cx_mch_id' => '平台商户ID', 'cx_mch_id' => '平台商户ID',
'name' => '商品名称', 'name' => '商品名称',
'subtitle' => '副标题', 'subtitle' => '副标题',
'original_price' => '原价', 'original_price' => '原价',
'cost_price' => '成本价', 'cost_price' => '成本价',
'detail' => '商品详情,图文', 'detail' => '商品详情,图文',
'cover_pic' => '商品缩略图', 'cover_pic' => '商品缩略图',
'pic_urls' => '商品轮播图', 'pic_urls' => '商品轮播图',
'video_url' => '商品视频', 'video_url' => '商品视频',
'unit' => '单位', 'unit' => '单位',
'created_at' => '添加时间', 'created_at' => '添加时间',
'updated_at' => '更新时间', 'updated_at' => '更新时间',
'deleted_at' => '删除时间', 'deleted_at' => '删除时间',
'is_delete' => '是否删除0=否1=是', 'is_delete' => '是否删除0=否1=是',
'type' => '商品类型0=实体商品 ', 'type' => '商品类型0=实体商品 ',
]; ];
} }
public function beforeSave($insert) { public function beforeSave($insert) {
if(parent::beforeSave($insert)){ if(parent::beforeSave($insert)){
if($this->isNewRecord){ if($this->isNewRecord){
$this->created_at = time(); $this->created_at = time();
} }
$this->updated_at = time(); $this->updated_at = time();
if($this->is_delete == 1) if($this->is_delete == 1)
$this->deleted_at = time(); $this->deleted_at = time();
$this->htmlTagFilter(); $this->htmlTagFilter();
return true; return true;
} else { } else {
return false; return false;
} }
} }
public function htmlTagFilter() public function htmlTagFilter()
{ {
$this->name = Model::htmlTagFilter($this->name); $this->name = Model::htmlTagFilter($this->name);
$this->subtitle = Model::htmlTagFilter($this->subtitle); $this->subtitle = Model::htmlTagFilter($this->subtitle);
$this->detail = Model::htmlTagFilter($this->detail); $this->detail = Model::htmlTagFilter($this->detail);
$this->cover_pic = Model::htmlTagFilter($this->cover_pic); $this->cover_pic = Model::htmlTagFilter($this->cover_pic);
$this->video_url = Model::htmlTagFilter($this->video_url); $this->video_url = Model::htmlTagFilter($this->video_url);
$this->unit = Model::htmlTagFilter($this->unit); $this->unit = Model::htmlTagFilter($this->unit);
} }
} }

View File

@ -1,435 +1,435 @@
<?php <?php
/** /**
* @author Any * @author Any
* @description KISS * @description KISS
* @date 2021年10月5日 * @date 2021年10月5日
* @version 1.0.0 * @version 1.0.0
* *
* _____LOG_____ * _____LOG_____
* *
*/ */
namespace app\models\common; namespace app\models\common;
use app\models\Goods; use app\models\Goods;
use app\models\GoodsAttr; use app\models\GoodsAttr;
use app\models\GoodsCat; use app\models\GoodsCat;
use app\models\GoodsHub; use app\models\GoodsHub;
use app\models\Cat; use app\models\Cat;
use app\models\Model; use app\models\Model;
use app\components\SiteHelper; use app\components\SiteHelper;
use app\components\SysConst; use app\components\SysConst;
use app\components\Serializer; use app\components\Serializer;
class CommonGoodsEditForm extends Model class CommonGoodsEditForm extends Model
{ {
public $name; public $name;
public $subtitle; public $subtitle;
public $original_price; public $original_price;
public $cost_price; public $cost_price;
public $detail = 0; public $detail = 0;
public $cover_pic; public $cover_pic;
public $pic_urls; public $pic_urls;
public $video_url; public $video_url;
public $unit; public $unit;
public $type; public $type;
public $price; public $price;
public $use_attr; public $use_attr;
public $attr; public $attr;
public $goods_stock; public $goods_stock;
public $virtual_sales; public $virtual_sales;
public $confine_count; public $confine_count;
public $freight_id; public $freight_id;
public $plugin_sign = 'goods'; public $plugin_sign = 'goods';
public $sort; public $sort;
public $cat_ids; public $cat_ids;
public $goods_no; public $goods_no;
public $goods_weight; public $goods_weight;
public $attrGroups; public $attrGroups;
public $model; public $model;
public $cx_mch_id; public $cx_mch_id;
public $newAttrs; public $newAttrs;
public $banner_urls; public $banner_urls;
public $video_banner_urls; public $video_banner_urls;
public $cat_id; public $cat_id;
public $cat1_id; public $cat1_id;
public $cat2_id; public $cat2_id;
public $cat3_id; public $cat3_id;
public $cat4_id; public $cat4_id;
public $date; public $date;
public function rules() public function rules()
{ {
return [ return [
[['name', 'subtitle', 'detail', 'cover_pic', 'video_url', 'unit', 'plugin_sign', 'goods_no',], 'trim'], [['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'], [['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'], [['original_price', 'cost_price', 'price', 'goods_weight'], 'number'],
[['type', 'use_attr', 'goods_stock', 'virtual_sales', 'confine_count', 'freight_id', 'sort', 'cx_mch_id'], 'integer'], [['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'], [['cat_id', 'cat1_id', 'cat2_id', 'cat3_id', 'cat4_id',], 'integer'],
[['pic_urls', 'cat_ids', 'model', 'attr', 'attrGroups'], 'safe'], [['pic_urls', 'cat_ids', 'model', 'attr', 'attrGroups'], 'safe'],
[['cost_price', 'original_price', 'price'], 'number', 'min' => 0], [['cost_price', 'original_price', 'price'], 'number', 'min' => 0],
[['cost_price', 'original_price', 'price'], 'number', 'max' => 9999999], [['cost_price', 'original_price', 'price'], 'number', 'max' => 9999999],
[['sort', 'virtual_sales', 'freight_id'], 'default', 'value' => 100], [['sort', 'virtual_sales', 'freight_id'], 'default', 'value' => 100],
[['confine_count', 'use_attr'], 'default', 'value' => 0], [['confine_count', 'use_attr'], 'default', 'value' => 0],
[['name', 'price', 'cover_pic', 'type', 'plugin_sign', 'banner_urls', 'model', 'cx_mch_id'], 'required'], [['name', 'price', 'cover_pic', 'type', 'plugin_sign', 'banner_urls', 'model', 'cx_mch_id'], 'required'],
]; ];
} }
public function attributeLabels() public function attributeLabels()
{ {
return [ return [
'name' => '商品名称', 'name' => '商品名称',
'subtitle' => '副标题', 'subtitle' => '副标题',
'original_price' => '原价', 'original_price' => '原价',
'cost_price' => '成本价', 'cost_price' => '成本价',
'detail' => '商品详情,图文', 'detail' => '商品详情,图文',
'cover_pic' => '商品缩略图', 'cover_pic' => '商品缩略图',
'pic_urls' => '商品轮播图', 'pic_urls' => '商品轮播图',
'video_url' => '商品视频', 'video_url' => '商品视频',
'unit' => '单位', 'unit' => '单位',
'type' => '商品类型0=实体商品 ', 'type' => '商品类型0=实体商品 ',
'status' => '上架状态0=下架1=上架', 'status' => '上架状态0=下架1=上架',
'price' => '售价', 'price' => '售价',
'use_attr' => '是否使用规格0=不使用1=使用', 'use_attr' => '是否使用规格0=不使用1=使用',
'attr' => '商品规格', 'attr' => '商品规格',
'goods_stock' => '商品库存', 'goods_stock' => '商品库存',
'virtual_sales' => '已出售量', 'virtual_sales' => '已出售量',
'confine_count' => '购物数量限制0=不限制', 'confine_count' => '购物数量限制0=不限制',
'freight_id' => '运费模板ID', 'freight_id' => '运费模板ID',
'plugin_sign' => '商品标示用于区分商品属于什么模块', 'plugin_sign' => '商品标示用于区分商品属于什么模块',
'sort' => '排序', 'sort' => '排序',
]; ];
} }
public function save() public function save()
{ {
if (!$this->validate()) { if (!$this->validate()) {
return $this->getModelError(); return $this->getModelError();
} }
$t = \Yii::$app->db->beginTransaction(); $t = \Yii::$app->db->beginTransaction();
if ($this->model->isNewRecord) { if ($this->model->isNewRecord) {
$this->model->cx_mch_id = $this->cx_mch_id; $this->model->cx_mch_id = $this->cx_mch_id;
$this->model->plugin_sign = $this->plugin_sign; $this->model->plugin_sign = $this->plugin_sign;
} }
$this->model->price = $this->price; $this->model->price = $this->price;
$this->model->goods_stock = empty($this->goods_stock) ? 9999 : $this->goods_stock; // 商品库存 $this->model->goods_stock = empty($this->goods_stock) ? 9999 : $this->goods_stock; // 商品库存
$this->model->virtual_sales = $this->virtual_sales; $this->model->virtual_sales = $this->virtual_sales;
$this->model->confine_count = $this->confine_count; $this->model->confine_count = $this->confine_count;
$this->model->freight_id = $this->freight_id; $this->model->freight_id = $this->freight_id;
$this->model->sort = 100; $this->model->sort = $this->sort;
$this->model->status = 1; $this->model->status = 1;
// $this->handleAttrGroups(); // $this->handleAttrGroups();
// $this->model->attr_groups = json_encode($this->attrGroups,JSON_UNESCAPED_UNICODE); // $this->model->attr_groups = json_encode($this->attrGroups,JSON_UNESCAPED_UNICODE);
$this->model->attr_groups = 1; //商品规格组 用不到看表 0 不需要规格组 $this->model->attr_groups = 1; //商品规格组 用不到看表 0 不需要规格组
$this->model->date = strtotime($this->date); $this->model->date = (int)strtotime($this->date."-01-01");
//保存商品基础信息 //保存商品基础信息
$res = $this->saveGoodsHub(); $res = $this->saveGoodsHub();
//保存商品基础信息 //保存商品基础信息
$res1 = $this->saveGoodsCat(); $res1 = $this->saveGoodsCat();
if ($res['code'] != 0 || $res1['code'] != 0) { if ($res['code'] != 0 || $res1['code'] != 0) {
$t->rollBack(); $t->rollBack();
return $res; return $res;
} }
if (!$this->model->save()) { if (!$this->model->save()) {
$t->rollBack(); $t->rollBack();
return $this->getModelError($this->model); return $this->getModelError($this->model);
} }
$t->commit(); $t->commit();
return $this->apiReturnSuccess('保存成功'); return $this->apiReturnSuccess('保存成功');
} }
//扩展其他 //扩展其他
protected function saveExtra() protected function saveExtra()
{ {
return $this->apiReturnSuccess(); return $this->apiReturnSuccess();
} }
private function saveGoodsHub() private function saveGoodsHub()
{ {
$goods_hub_id = $this->model->isNewRecord ? 0 : $this->model->goods_hub_id; $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]); $goods_hub = GoodsHub::findOne(['id' => $goods_hub_id, 'is_delete' => 0, 'cx_mch_id' => $this->cx_mch_id]);
if ($goods_hub == null) { if ($goods_hub == null) {
$goods_hub = new GoodsHub(); $goods_hub = new GoodsHub();
$goods_hub->cx_mch_id = $this->cx_mch_id; $goods_hub->cx_mch_id = $this->cx_mch_id;
} }
$goods_hub->name = $this->name; $goods_hub->name = $this->name;
$goods_hub->subtitle = $this->subtitle; $goods_hub->subtitle = $this->subtitle;
$goods_hub->original_price = $this->original_price ? $this->original_price : $this->price; $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->cost_price = $this->cost_price ? $this->cost_price : $this->price;
$goods_hub->detail = $this->detail; $goods_hub->detail = $this->detail;
$goods_hub->cover_pic = $this->cover_pic; $goods_hub->cover_pic = $this->cover_pic;
$goods_hub->banner_urls = $this->banner_urls; $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); $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; $goods_hub->video_banner_urls = $video_banner_urls;
$pic_urls = is_string($this->pic_urls) ? $this->pic_urls : json_encode($this->pic_urls); $pic_urls = is_string($this->pic_urls) ? $this->pic_urls : json_encode($this->pic_urls);
$goods_hub->pic_urls = $pic_urls; $goods_hub->pic_urls = $pic_urls;
$video_urls = is_string($this->video_url) ? $this->video_url : json_encode($this->video_url); $video_urls = is_string($this->video_url) ? $this->video_url : json_encode($this->video_url);
$goods_hub->video_url = $video_urls; $goods_hub->video_url = $video_urls;
$goods_hub->unit = $this->unit; $goods_hub->unit = $this->unit;
$goods_hub->type = $this->type; $goods_hub->type = $this->type;
if (!$goods_hub->save()) { if (!$goods_hub->save()) {
return $this->getModelError($goods_hub); return $this->getModelError($goods_hub);
} }
$this->model->goods_hub_id = $goods_hub->id; $this->model->goods_hub_id = $goods_hub->id;
return $this->apiReturnSuccess(); return $this->apiReturnSuccess();
} }
//保存商品规格 //保存商品规格
private function saveGoodsAttr() private function saveGoodsAttr()
{ {
if ((int)$this->use_attr === 0) { if ((int)$this->use_attr === 0) {
$this->model->use_attr = 0; $this->model->use_attr = 0;
// 未使用规格就添加默认规格 // 未使用规格就添加默认规格
$res = $this->setDefaultAttr(); $res = $this->setDefaultAttr();
if ($res['code'] != 0) if ($res['code'] != 0)
return $res; return $res;
$attrPicList = []; $attrPicList = [];
} else { } else {
$this->handleAttr(); $this->handleAttr();
// 多规格数据处理 // 多规格数据处理
$this->newAttrs = $this->attr; $this->newAttrs = $this->attr;
$attrPicList = array_column($this->attrGroups[0]['attr_list'], 'cover_pic', 'attr_id'); $attrPicList = array_column($this->attrGroups[0]['attr_list'], 'cover_pic', 'attr_id');
} }
$oldAttr = GoodsAttr::find() $oldAttr = GoodsAttr::find()
->where(['is_delete' => 0, 'goods_id' => $this->model->id]) ->where(['is_delete' => 0, 'goods_id' => $this->model->id])
->select('id') ->select('id')
->asArray() ->asArray()
->all(); ->all();
// 是否为新增 // 是否为新增
if (!$this->model->isNewRecord) { if (!$this->model->isNewRecord) {
GoodsAttr::updateAll(['is_delete' => 1,], ['goods_id' => $this->model->id, 'is_delete' => 0]); GoodsAttr::updateAll(['is_delete' => 1,], ['goods_id' => $this->model->id, 'is_delete' => 0]);
} }
// 旧规格ID // 旧规格ID
$oldAttrIds = []; $oldAttrIds = [];
$newAttrIds = []; $newAttrIds = [];
foreach ($oldAttr as $oldItem) { foreach ($oldAttr as $oldItem) {
$oldAttrIds[] = $oldItem['id']; $oldAttrIds[] = $oldItem['id'];
} }
$goodsStock = 0; $goodsStock = 0;
foreach ($this->newAttrs as $newAttr) { foreach ($this->newAttrs as $newAttr) {
$goodsStock += $newAttr['stock']; $goodsStock += $newAttr['stock'];
// 记录规格ID数组 // 记录规格ID数组
$signIds = ''; $signIds = '';
foreach ($newAttr['attr_list'] as $aLItem) { foreach ($newAttr['attr_list'] as $aLItem) {
$signIds .= $signIds ? ':' . (int)$aLItem['attr_id'] : (int)$aLItem['attr_id']; $signIds .= $signIds ? ':' . (int)$aLItem['attr_id'] : (int)$aLItem['attr_id'];
} }
// TODO 待修改 // TODO 待修改
// 判断规格是需要新增还是更新 // 判断规格是需要新增还是更新
$goodsAttr = null; $goodsAttr = null;
if ($this->model->id) { if ($this->model->id) {
$goodsAttr = GoodsAttr::findOne([ $goodsAttr = GoodsAttr::findOne([
'id' => isset($newAttr['id']) ? $newAttr['id'] : 0, 'id' => isset($newAttr['id']) ? $newAttr['id'] : 0,
'goods_id' => $this->model->id 'goods_id' => $this->model->id
]); ]);
if ($goodsAttr == null && count($this->newAttrs) == 1) { if ($goodsAttr == null && count($this->newAttrs) == 1) {
$goodsAttr = GoodsAttr::findOne([ $goodsAttr = GoodsAttr::findOne([
'sign_id' => $signIds, 'sign_id' => $signIds,
'goods_id' => $this->model->id 'goods_id' => $this->model->id
]); ]);
} }
} }
if ($goodsAttr) { if ($goodsAttr) {
$goodsAttr->is_delete = 0; $goodsAttr->is_delete = 0;
} else { } else {
$goodsAttr = new GoodsAttr(); $goodsAttr = new GoodsAttr();
} }
if ($newAttr['stock'] > 9999999) { if ($newAttr['stock'] > 9999999) {
return $this->apiReturnError('商品总库存不能大于9999999'); return $this->apiReturnError('商品总库存不能大于9999999');
} }
$goodsAttr->goods_id = $this->model->id; $goodsAttr->goods_id = $this->model->id;
$goodsAttr->sign_id = $signIds; $goodsAttr->sign_id = $signIds;
$goodsAttr->stock = $newAttr['stock']; $goodsAttr->stock = $newAttr['stock'];
$goodsAttr->price = $newAttr['price']; $goodsAttr->price = $newAttr['price'];
$goodsAttr->serial_no = $newAttr['serial_no']; $goodsAttr->serial_no = $newAttr['serial_no'];
$goodsAttr->weight = $newAttr['weight'] ?: 0; $goodsAttr->weight = $newAttr['weight'] ?: 0;
$key = strstr($signIds, ':', true) ?: $signIds; $key = strstr($signIds, ':', true) ?: $signIds;
$goodsAttr->cover_pic = !empty($newAttr['cover_pic']) ? $newAttr['cover_pic'] : $this->cover_pic; $goodsAttr->cover_pic = !empty($newAttr['cover_pic']) ? $newAttr['cover_pic'] : $this->cover_pic;
$res = $goodsAttr->save(); $res = $goodsAttr->save();
if (!$res) { if (!$res) {
return $this->getModelError($goodsAttr); return $this->getModelError($goodsAttr);
} }
$newAttrIds[] = $goodsAttr->id; $newAttrIds[] = $goodsAttr->id;
} }
if ($goodsStock > 9999999) { if ($goodsStock > 9999999) {
return $this->apiReturnError('商品总库存不能大于9999999'); return $this->apiReturnError('商品总库存不能大于9999999');
} }
$this->model->goods_stock = $goodsStock; $this->model->goods_stock = $goodsStock;
$res = $this->model->save(); $res = $this->model->save();
if (!$res) { if (!$res) {
return $this->getModelError($this->model); return $this->getModelError($this->model);
} }
return $this->apiReturnSuccess(); return $this->apiReturnSuccess();
} }
private function handleAttrGroups() private function handleAttrGroups()
{ {
$this->attrGroups = $this->addAttrGroupsId($this->attrGroups); $this->attrGroups = $this->addAttrGroupsId($this->attrGroups);
} }
private function handleAttr() private function handleAttr()
{ {
foreach ($this->attr as &$item) { foreach ($this->attr as &$item) {
foreach ($item['attr_list'] as &$alItem) { foreach ($item['attr_list'] as &$alItem) {
$alItem['attr_group_id'] = $this->newAttrGroupList[$alItem['attr_group_name']]; $alItem['attr_group_id'] = $this->newAttrGroupList[$alItem['attr_group_name']];
$alItem['attr_id'] = $this->newAttrList[$alItem['attr_name']]; $alItem['attr_id'] = $this->newAttrList[$alItem['attr_name']];
} }
unset($alItem); unset($alItem);
} }
unset($item); unset($item);
} }
private $newAttrGroupList = []; private $newAttrGroupList = [];
private $newAttrList = []; private $newAttrList = [];
private $signArr = []; private $signArr = [];
private function addAttrGroupsId($list, &$id = 1) private function addAttrGroupsId($list, &$id = 1)
{ {
$newId = 1; $newId = 1;
foreach ($list as $key => $item) { foreach ($list as $key => $item) {
if (isset($item['attr_list'])) { if (isset($item['attr_list'])) {
$this->newAttrGroupList[$item['attr_group_name']] = $newId; $this->newAttrGroupList[$item['attr_group_name']] = $newId;
$list[$key]['attr_group_id'] = $newId++; $list[$key]['attr_group_id'] = $newId++;
$newItemList = $this->addAttrGroupsId($item['attr_list'], $id); $newItemList = $this->addAttrGroupsId($item['attr_list'], $id);
$list[$key]['attr_list'] = $newItemList; $list[$key]['attr_list'] = $newItemList;
} else { } else {
if (isset($this->signArr[$item['attr_name']])) { if (isset($this->signArr[$item['attr_name']])) {
$this->newAttrList[$item['attr_name']] = $this->signArr[$item['attr_name']]; $this->newAttrList[$item['attr_name']] = $this->signArr[$item['attr_name']];
$list[$key]['attr_id'] = $this->signArr[$item['attr_name']]; $list[$key]['attr_id'] = $this->signArr[$item['attr_name']];
} else { } else {
$this->signArr[$item['attr_name']] = $id; $this->signArr[$item['attr_name']] = $id;
$this->newAttrList[$item['attr_name']] = $id; $this->newAttrList[$item['attr_name']] = $id;
$list[$key]['attr_id'] = $id++; $list[$key]['attr_id'] = $id++;
} }
} }
} }
return $list; return $list;
} }
/** /**
* 添加默认规格 * 添加默认规格
*/ */
private function setDefaultAttr() private function setDefaultAttr()
{ {
$attrList = [ $attrList = [
[ [
'attr_group_name' => '规格', 'attr_group_name' => '规格',
'attr_group_id' => 1, 'attr_group_id' => 1,
'attr_id' => 1, 'attr_id' => 1,
'attr_name' => '默认', 'attr_name' => '默认',
] ]
]; ];
$count = 1; $count = 1;
$attrGroups = []; $attrGroups = [];
foreach ($attrList as &$item) { foreach ($attrList as &$item) {
$item['attr_group_id'] = $count; $item['attr_group_id'] = $count;
$count++; $count++;
$item['attr_id'] = $count; $item['attr_id'] = $count;
$count++; $count++;
$newItem = [ $newItem = [
'attr_group_id' => $item['attr_group_id'], 'attr_group_id' => $item['attr_group_id'],
'attr_group_name' => $item['attr_group_name'], 'attr_group_name' => $item['attr_group_name'],
'attr_list' => [ 'attr_list' => [
[ [
'attr_id' => $item['attr_id'], 'attr_id' => $item['attr_id'],
'attr_name' => $item['attr_name'] 'attr_name' => $item['attr_name']
] ]
] ]
]; ];
$attrGroups[] = $newItem; $attrGroups[] = $newItem;
} }
unset($item); unset($item);
// 未使用规格 就添加一条默认规格 // 未使用规格 就添加一条默认规格
$newAttrs = [ $newAttrs = [
[ [
'attr_list' => $attrList, 'attr_list' => $attrList,
'stock' => $this->goods_stock, 'stock' => $this->goods_stock,
'price' => $this->price, 'price' => $this->price,
'serial_no' => $this->goods_no ? $this->goods_no : '', 'serial_no' => $this->goods_no ? $this->goods_no : '',
'weight' => $this->goods_weight ? $this->goods_weight : 0, 'weight' => $this->goods_weight ? $this->goods_weight : 0,
'cover_pic' => $this->cover_pic, 'cover_pic' => $this->cover_pic,
] ]
]; ];
// 未使用规格情况下要把上一次的规格ID 存回去,不然规格记录会重复添加 // 未使用规格情况下要把上一次的规格ID 存回去,不然规格记录会重复添加
if (count($this->attr) === 1 && isset($this->attr[0]['id'])) { if (count($this->attr) === 1 && isset($this->attr[0]['id'])) {
$newAttrs[0]['id'] = $this->attr[0]['id']; $newAttrs[0]['id'] = $this->attr[0]['id'];
} }
$this->model->attr_groups = (new Serializer)->encode($attrGroups); $this->model->attr_groups = (new Serializer)->encode($attrGroups);
$res = $this->model->save(); $res = $this->model->save();
if (!$res) { if (!$res) {
return $this->getModelError($this->model); return $this->getModelError($this->model);
} }
$this->newAttrs = $newAttrs; $this->newAttrs = $newAttrs;
return $this->apiReturnSuccess(); return $this->apiReturnSuccess();
} }
//保存商品分类 //保存商品分类
protected function saveGoodsCat() protected function saveGoodsCat()
{ {
$type = Cat::TYPE_GOODS; $type = Cat::TYPE_GOODS;
$goods_hub_id = $this->model->goods_hub_id; $goods_hub_id = $this->model->goods_hub_id;
$goods_cat = GoodsCat::findOne(['goods_hub_id' => $goods_hub_id, 'is_delete' => 0]); $goods_cat = GoodsCat::findOne(['goods_hub_id' => $goods_hub_id, 'is_delete' => 0]);
if ($goods_cat == null) { if ($goods_cat == null) {
$goods_cat = new GoodsCat(); $goods_cat = new GoodsCat();
} }
$goods_cat->goods_hub_id = $goods_hub_id; $goods_cat->goods_hub_id = $goods_hub_id;
$goods_cat->cat_id = $this->cat_id; $goods_cat->cat_id = $this->cat_id;
$goods_cat->cat1_id = $this->cat1_id; $goods_cat->cat1_id = $this->cat1_id;
$goods_cat->cat2_id = $this->cat2_id; $goods_cat->cat2_id = $this->cat2_id;
$goods_cat->cat3_id = $this->cat3_id; $goods_cat->cat3_id = $this->cat3_id;
$goods_cat->cat4_id = $this->cat4_id; $goods_cat->cat4_id = $this->cat4_id;
$goods_cat->is_delete = 0; $goods_cat->is_delete = 0;
$res = $goods_cat->save(); $res = $goods_cat->save();
if (!$res) { if (!$res) {
return $this->getModelError($goods_cat); return $this->getModelError($goods_cat);
} }
return $this->apiReturnSuccess(); return $this->apiReturnSuccess();
} }
} }

View File

@ -1,317 +1,317 @@
<?php <?php
/** /**
* @author Any * @author Any
* @description KISS * @description KISS
* @date 2021年10月5日 * @date 2021年10月5日
* @version 1.0.0 * @version 1.0.0
* *
* _____LOG_____ * _____LOG_____
* *
*/ */
namespace app\models\common; namespace app\models\common;
use app\models\Cat1; use app\models\Cat1;
use app\models\Cat2; use app\models\Cat2;
use app\models\Cat3; use app\models\Cat3;
use app\models\Cat4; use app\models\Cat4;
use app\models\Goods; use app\models\Goods;
use app\models\GoodsAttr; use app\models\GoodsAttr;
use app\models\GoodsCat; use app\models\GoodsCat;
use app\models\GoodsHub; use app\models\GoodsHub;
use app\models\integral\mall\IntegralMallGoods; use app\models\integral\mall\IntegralMallGoods;
use app\models\Cat; use app\models\Cat;
use app\models\Model; use app\models\Model;
use yii\data\Pagination; use yii\data\Pagination;
use app\components\SiteHelper; use app\components\SiteHelper;
use app\components\SysConst; use app\components\SysConst;
class CommonGoodsListForm extends Model class CommonGoodsListForm extends Model
{ {
public $keywords; public $keywords;
public $limit; public $limit;
public $page; public $page;
public $cat_id; public $cat_id;
public $cx_mch_id; public $cx_mch_id;
public $status; public $status;
public $goods_id; public $goods_id;
public $start_time; public $start_time;
public $end_time; public $end_time;
public $plugin_sign; public $plugin_sign;
private $fields; private $fields;
public $cat1_id; public $cat1_id;
public $cat2_id; public $cat2_id;
public $cat3_id; public $cat3_id;
public $cat4_id; public $cat4_id;
public $cat5_id; public $cat5_id;
public function rules() public function rules()
{ {
return [ return [
[['keywords', 'plugin_sign',], 'trim'], [['keywords', 'plugin_sign',], 'trim'],
[['keywords', 'plugin_sign',], 'string'], [['keywords', 'plugin_sign',], 'string'],
[['limit', 'page', 'cx_mch_id', 'status', 'goods_id', 'cat_id'], 'integer'], [['limit', 'page', 'cx_mch_id', 'status', 'goods_id', 'cat_id'], 'integer'],
[['cat_id', 'cat1_id', 'cat2_id', 'cat3_id', 'cat4_id'], 'integer'], [['cat_id', 'cat1_id', 'cat2_id', 'cat3_id', 'cat4_id'], 'integer'],
[['page'], 'default', 'value' => 1], [['page'], 'default', 'value' => 1],
[['limit'], 'default', 'value' => 20], [['limit'], 'default', 'value' => 20],
[['status'], 'in', 'range' => [0, 1, 2]], [['status'], 'in', 'range' => [0, 1, 2]],
[['cx_mch_id'], 'required'], [['cx_mch_id'], 'required'],
[['start_time', 'end_time',], 'safe'], [['start_time', 'end_time',], 'safe'],
[['goods_id'], 'required', 'on' => 'detail'], [['goods_id'], 'required', 'on' => 'detail'],
]; ];
} }
public function search() public function search()
{ {
if (!$this->validate()) { if (!$this->validate()) {
return $this->getModelError(); return $this->getModelError();
} }
$cat_query = GoodsCat::find() $cat_query = GoodsCat::find()
->where([ ->where([
'is_delete' => 0, 'is_delete' => 0,
]) ])
->select('goods_hub_id,cat_id,cat1_id,cat2_id,cat3_id,cat4_id'); ->select('goods_hub_id,cat_id,cat1_id,cat2_id,cat3_id,cat4_id');
$query = $this->getQuery($cat_query); $query = $this->getQuery($cat_query);
$query = $query->where([ $query = $query->where([
'g.cx_mch_id' => $this->cx_mch_id, 'g.cx_mch_id' => $this->cx_mch_id,
// 'g.is_delete' => 0, 'g.is_delete' => 0,
// 'gh.is_delete' => 0, // 'gh.is_delete' => 0,
// 'g.plugin_sign' => $this->plugin_sign, // 'g.plugin_sign' => $this->plugin_sign,
]) ])
->andFilterWhere([ ->andFilterWhere([
'OR', 'OR',
['LIKE', 'gh.name', $this->keywords], ['LIKE', 'gh.name', $this->keywords],
// ['LIKE', 'gh.subtitle', $this->keywords], // ['LIKE', 'gh.subtitle', $this->keywords],
]) ])
->andFilterWhere([ ->andFilterWhere([
'g.id' => $this->goods_id, 'g.id' => $this->goods_id,
'gc.cat_id' => $this->cat_id, 'gc.cat_id' => $this->cat_id,
'gc.cat1_id' => $this->cat1_id, 'gc.cat1_id' => $this->cat1_id,
'gc.cat2_id' => $this->cat2_id, 'gc.cat2_id' => $this->cat2_id,
'gc.cat3_id' => $this->cat3_id, 'gc.cat3_id' => $this->cat3_id,
'gc.cat4_id' => $this->cat4_id, 'gc.cat4_id' => $this->cat4_id,
]); ]);
if ($this->status == 2) { if ($this->status == 2) {
$query = $query->andWhere(['g.goods_stock' => 0]);//售罄 $query = $query->andWhere(['g.goods_stock' => 0]);//售罄
} else { } else {
$query = $query->andFilterWhere(['g.status' => $this->status]); $query = $query->andFilterWhere(['g.status' => $this->status]);
} }
$query = $this->switchTime($query); $query = $this->switchTime($query);
$query = $this->getFields($query); $query = $this->getFields($query);
$count_query = clone $query; $count_query = clone $query;
$count = $count_query->count(); $count = $count_query->count();
$pagination = new Pagination(['pageSize' => $this->limit, 'totalCount' => $count, 'page' => $this->page - 1]); $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 = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['g.sort' => SORT_DESC, 'g.created_at' => SORT_DESC])->asArray()->all();
$list = $this->handleList($list); $list = $this->handleList($list);
//是否已经全部加载 //是否已经全部加载
$end_flag = $this->page > $pagination->pageCount ? true : false; $end_flag = $this->page > $pagination->pageCount ? true : false;
return [ return [
'code' => 0, 'code' => 0,
'msg' => 'ok', 'msg' => 'ok',
'data' => $list, 'data' => $list,
'count' => $count, 'count' => $count,
'page_size' => $this->limit, 'page_size' => $this->limit,
'page_count' => $pagination->pageCount, 'page_count' => $pagination->pageCount,
'page_no' => $this->page, 'page_no' => $this->page,
'end_flag' => $end_flag 'end_flag' => $end_flag
]; ];
} }
protected function getQuery($cat_query) protected function getQuery($cat_query)
{ {
$query = Goods::find()->alias('g') $query = Goods::find()->alias('g')
->leftJoin(['gh' => GoodsHub::tableName()], 'gh.id=g.goods_hub_id') ->leftJoin(['gh' => GoodsHub::tableName()], 'gh.id=g.goods_hub_id')
->leftJoin(['gc' => $cat_query], 'gc.goods_hub_id=gh.id'); ->leftJoin(['gc' => $cat_query], 'gc.goods_hub_id=gh.id');
return $query; return $query;
} }
public function setFields($fields) public function setFields($fields)
{ {
$this->fields = $fields; $this->fields = $fields;
} }
protected function getFields($query) protected function getFields($query)
{ {
$fields = is_array($this->fields) ? implode(',', $this->fields) : $this->fields; $fields = is_array($this->fields) ? implode(',', $this->fields) : $this->fields;
return $query->select($fields); return $query->select($fields);
} }
protected function handleList($list) protected function handleList($list)
{ {
foreach ($list as $index => $item) { foreach ($list as $index => $item) {
$item['status_cn'] = $item['status'] == Goods::STATUS_ONLINE ? '正常' : '隐藏'; $item['status_cn'] = $item['status'] == Goods::STATUS_ONLINE ? '正常' : '隐藏';
$item['created_at_cn'] = date('Y-m-d H:i:s', $item['created_at']); $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['date_at_cn'] = date('Y-m-d', $item['date']);
$item['cat_list'] = $this->getCatList($item['goods_hub_id']); $item['cat_list'] = $this->getCatList($item['goods_hub_id']);
$item['cat1_list'] = $this->getCat1List($item['goods_hub_id']); $item['cat1_list'] = $this->getCat1List($item['goods_hub_id']);
$item['cat2_list'] = $this->getCat2List($item['goods_hub_id']); $item['cat2_list'] = $this->getCat2List($item['goods_hub_id']);
$item['cat3_list'] = $this->getCat3List($item['goods_hub_id']); $item['cat3_list'] = $this->getCat3List($item['goods_hub_id']);
$item['cat4_list'] = $this->getCat4List($item['goods_hub_id']); $item['cat4_list'] = $this->getCat4List($item['goods_hub_id']);
$item['cover_pic'] = SiteHelper::getFullUrl($item['cover_pic']); $item['cover_pic'] = SiteHelper::getFullUrl($item['cover_pic']);
if ($this->scenario == 'detail') { if ($this->scenario == 'detail') {
$item['detail'] = SiteHelper::repairContent($item['detail']); $item['detail'] = SiteHelper::repairContent($item['detail']);
$item['pic_urls'] = $this->fixPicUrls($item['pic_urls']); $item['pic_urls'] = $this->fixPicUrls($item['pic_urls']);
$item['video_url'] = SiteHelper::getFullUrl($item['video_url']); $item['video_url'] = SiteHelper::getFullUrl($item['video_url']);
$item['goods_sales'] = $item['virtaul_sales'] + $item['sales']; $item['goods_sales'] = $item['virtaul_sales'] + $item['sales'];
$item['attr_groups'] = empty($item['attr_groups']) ? [] : json_decode($item['attr_groups'], true); $item['attr_groups'] = empty($item['attr_groups']) ? [] : json_decode($item['attr_groups'], true);
$item['attr'] = $this->getAttr($item['id']); $item['attr'] = $this->getAttr($item['id']);
} }
$list[$index] = $item; $list[$index] = $item;
} }
return $list; return $list;
} }
protected function switchTime($query) protected function switchTime($query)
{ {
if (!empty($this->start_time)) { if (!empty($this->start_time)) {
$query = $query->andWhere([ $query = $query->andWhere([
'>', '>',
'g.created_at', 'g.created_at',
strtotime($this->start_time) strtotime($this->start_time)
]); ]);
} }
if (!empty($this->end_time)) { if (!empty($this->end_time)) {
$query = $query->andWhere([ $query = $query->andWhere([
'<', '<',
'g.created_at', 'g.created_at',
strtotime($this->end_time) strtotime($this->end_time)
]); ]);
} }
return $query; return $query;
} }
protected function getCatList($goods_hub_id) protected function getCatList($goods_hub_id)
{ {
switch ($this->plugin_sign) { switch ($this->plugin_sign) {
case SysConst::$cxPluginSceneMall: case SysConst::$cxPluginSceneMall:
$type = Cat::TYPE_GOODS; $type = Cat::TYPE_GOODS;
break; break;
case SysConst::$cxPluginSceneIntegralMall: case SysConst::$cxPluginSceneIntegralMall:
$type = Cat::TYPE_INTEGRAL_GOODS; $type = Cat::TYPE_INTEGRAL_GOODS;
break; break;
//@TODO 其他 //@TODO 其他
default: default:
$type = Cat::TYPE_GOODS; $type = Cat::TYPE_GOODS;
} }
$list = GoodsCat::find()->alias('gc') $list = GoodsCat::find()->alias('gc')
->leftJoin(['c' => Cat::tableName()], 'c.id=gc.cat_id') ->leftJoin(['c' => Cat::tableName()], 'c.id=gc.cat_id')
->where([ ->where([
'gc.is_delete' => 0, 'gc.is_delete' => 0,
'gc.goods_hub_id' => $goods_hub_id, 'gc.goods_hub_id' => $goods_hub_id,
'c.is_delete' => 0, 'c.is_delete' => 0,
'c.type' => $type, 'c.type' => $type,
]) ])
->select('c.name,c.id as cat_id')->asArray()->all(); ->select('c.name,c.id as cat_id')->asArray()->all();
return $list; return $list;
} }
protected function getCat1List($goods_hub_id) protected function getCat1List($goods_hub_id)
{ {
$list = GoodsCat::find()->alias('gc') $list = GoodsCat::find()->alias('gc')
->leftJoin(['c' => Cat1::tableName()], 'c.id=gc.cat1_id') ->leftJoin(['c' => Cat1::tableName()], 'c.id=gc.cat1_id')
->where([ ->where([
'gc.is_delete' => 0, 'gc.is_delete' => 0,
'gc.goods_hub_id' => $goods_hub_id, 'gc.goods_hub_id' => $goods_hub_id,
'c.is_delete' => 0, 'c.is_delete' => 0,
]) ])
->select('c.name,c.id as cat_id')->asArray()->all(); ->select('c.name,c.id as cat_id')->asArray()->all();
return $list; return $list;
} }
protected function getCat2List($goods_hub_id) protected function getCat2List($goods_hub_id)
{ {
$list = GoodsCat::find()->alias('gc') $list = GoodsCat::find()->alias('gc')
->leftJoin(['c' => Cat2::tableName()], 'c.id=gc.cat2_id') ->leftJoin(['c' => Cat2::tableName()], 'c.id=gc.cat2_id')
->where([ ->where([
'gc.is_delete' => 0, 'gc.is_delete' => 0,
'gc.goods_hub_id' => $goods_hub_id, 'gc.goods_hub_id' => $goods_hub_id,
'c.is_delete' => 0, 'c.is_delete' => 0,
]) ])
->select('c.name,c.id as cat_id')->asArray()->all(); ->select('c.name,c.id as cat_id')->asArray()->all();
return $list; return $list;
} }
protected function getCat3List($goods_hub_id) protected function getCat3List($goods_hub_id)
{ {
$list = GoodsCat::find()->alias('gc') $list = GoodsCat::find()->alias('gc')
->leftJoin(['c' => Cat3::tableName()], 'c.id=gc.cat3_id') ->leftJoin(['c' => Cat3::tableName()], 'c.id=gc.cat3_id')
->where([ ->where([
'gc.is_delete' => 0, 'gc.is_delete' => 0,
'gc.goods_hub_id' => $goods_hub_id, 'gc.goods_hub_id' => $goods_hub_id,
'c.is_delete' => 0, 'c.is_delete' => 0,
]) ])
->select('c.name,c.id as cat_id')->asArray()->all(); ->select('c.name,c.id as cat_id')->asArray()->all();
return $list; return $list;
} }
protected function getCat4List($goods_hub_id) protected function getCat4List($goods_hub_id)
{ {
$list = GoodsCat::find()->alias('gc') $list = GoodsCat::find()->alias('gc')
->leftJoin(['c' => Cat4::tableName()], 'c.id=gc.cat4_id') ->leftJoin(['c' => Cat4::tableName()], 'c.id=gc.cat4_id')
->where([ ->where([
'gc.is_delete' => 0, 'gc.is_delete' => 0,
'gc.goods_hub_id' => $goods_hub_id, 'gc.goods_hub_id' => $goods_hub_id,
'c.is_delete' => 0, 'c.is_delete' => 0,
]) ])
->select('c.name,c.id as cat_id')->asArray()->all(); ->select('c.name,c.id as cat_id')->asArray()->all();
return $list; return $list;
} }
protected function fixPicUrls($pic_urls) protected function fixPicUrls($pic_urls)
{ {
$pic_urls = is_string($pic_urls) && !empty($pic_urls) ? json_decode($pic_urls, true) : $pic_urls; $pic_urls = is_string($pic_urls) && !empty($pic_urls) ? json_decode($pic_urls, true) : $pic_urls;
foreach ($pic_urls as $index => $item) { foreach ($pic_urls as $index => $item) {
$item = SiteHelper::getFullUrl($item); $item = SiteHelper::getFullUrl($item);
$pic_urls[$index] = $item; $pic_urls[$index] = $item;
} }
return $pic_urls; return $pic_urls;
} }
//获取商品规格 //获取商品规格
private function getAttr($goods_id) private function getAttr($goods_id)
{ {
$attr = GoodsAttr::find()->alias('gr') $attr = GoodsAttr::find()->alias('gr')
->where([ ->where([
'gr.goods_id' => $goods_id, 'gr.goods_id' => $goods_id,
'gr.is_delete' => 0 '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') ->select('gr.id,gr.goods_id,gr.price,gr.sign_id,gr.stock,gr.serial_no,gr.weight,gr.cover_pic')
->asArray()->all(); ->asArray()->all();
foreach ($attr as $index => $item) { foreach ($attr as $index => $item) {
$item['cover_pic'] = SiteHelper::getFullUrl($item['cover_pic']); $item['cover_pic'] = SiteHelper::getFullUrl($item['cover_pic']);
$attr[$index] = $item; $attr[$index] = $item;
} }
return $attr; return $attr;
} }
} }

View File

@ -194,7 +194,7 @@ class GoodsController extends Controller
$return_url = \Yii::$app->request->referrer; $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_url);
// var_dump($model->goodsHub->video_banner_urls); // var_dump($model->goodsHub->video_banner_urls);

View File

@ -40,13 +40,14 @@ class BoxEditForm extends AdminModel
public $updated_at; public $updated_at;
public $is_delete; public $is_delete;
public $deleted_at; public $deleted_at;
public $sort;
public function rules() public function rules()
{ {
return [ 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'], [['model'], 'safe'],
[['notice', 'cover_pic'], 'string'], [['notice', 'cover_pic'], 'string'],
[['goods_id', 'bj_id', 'notice', 'cover_pic'], 'required'], [['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->cover_pic = $this->cover_pic;
$this->model->status = $this->status; $this->model->status = $this->status;
$this->model->notice = $this->notice; $this->model->notice = $this->notice;
$this->model->sort = $this->sort;
if (!$this->model->save()) { if (!$this->model->save()) {
return $this->getModelError($this->model); return $this->getModelError($this->model);

View File

@ -56,7 +56,7 @@ class BoxListForm extends AdminModel
->leftJoin(['goods' => Goods::tableName()], 'b.goods_id=goods.id') ->leftJoin(['goods' => Goods::tableName()], 'b.goods_id=goods.id')
->leftJoin(['goodHub' => GoodsHub::tableName()], 'goods.goods_hub_id=goodHub.id') ->leftJoin(['goodHub' => GoodsHub::tableName()], 'goods.goods_hub_id=goodHub.id')
->leftJoin(['storeBj' => StoreBj::tableName()], 'b.bj_id=storeBj.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([ ->where([
'b.is_delete' => 0 'b.is_delete' => 0
]) ])
@ -65,7 +65,7 @@ class BoxListForm extends AdminModel
$count = $query->count(); $count = $query->count();
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $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) { foreach ($list as $index => $item) {
// $item['business'] = $item['begin_time'] . '-' . $item['end_time']; // $item['business'] = $item['begin_time'] . '-' . $item['end_time'];
$item['created_at_cn'] = date("Y-m-d H:i", $item['created_at']); $item['created_at_cn'] = date("Y-m-d H:i", $item['created_at']);

View File

@ -1,329 +1,344 @@
<?php <?php
/** /**
* @author Any * @author Any
* @description KISS * @description KISS
* @date 2021年10月5日 * @date 2021年10月5日
* @version 1.0.0 * @version 1.0.0
* *
* _____LOG_____ * _____LOG_____
* *
*/ */
use app\widgets\PickFile; use app\widgets\PickFile;
use app\widgets\GoodsSku; use app\widgets\GoodsSku;
use app\assets\UeditorAsset; use app\assets\UeditorAsset;
UeditorAsset::register($this); UeditorAsset::register($this);
$this->title = $model->isNewRecord ? '添加冠军' : '编辑冠军'; $this->title = $model->isNewRecord ? '添加冠军' : '编辑冠军';
$this->params['breadcrumbs'][] = ['label' => '冠军', 'url' => [\Yii::$app->urlManager->createUrl(["admin/mall/goods/index"])]]; $this->params['breadcrumbs'][] = ['label' => '冠军', 'url' => [\Yii::$app->urlManager->createUrl(["admin/mall/goods/index"])]];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="layui-fluid"> <div class="layui-fluid">
<div class="layui-card"> <div class="layui-card">
<div class="layui-card-header"><?= $this->title ?></div> <div class="layui-card-header"><?= $this->title ?></div>
<div class="layui-card-body"> <div class="layui-card-body">
<div class="layui-row"> <div class="layui-row">
<div class="layui-col-md12"> <div class="layui-col-md12">
<div class="layui-form"> <div class="layui-form">
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label required">冠军名称</label> <label class="layui-form-label required">冠军名称</label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<input name="name" placeholder="请输入冠军名称" autocomplete="off" <input name="name" placeholder="请输入冠军名称" autocomplete="off"
class="layui-input" value="<?= $model->goodsHub->name ?>" lay-verify="required"> class="layui-input" value="<?= $model->goodsHub->name ?>" lay-verify="required">
</div> </div>
<div class="layui-form-mid layui-word-aux"></div> <div class="layui-form-mid layui-word-aux"></div>
</div> </div>
<?= PickFile::widget([ <?= PickFile::widget([
'accept' => 'images', 'accept' => 'images',
'id' => 'cover_pic', 'id' => 'cover_pic',
'name' => 'cover_pic', 'name' => 'cover_pic',
'label' => '封面', 'label' => '封面',
'value' => $model->goodsHub ? $model->goodsHub->cover_pic : '', 'value' => $model->goodsHub ? $model->goodsHub->cover_pic : '',
'tip' => '图片大小750×750', 'tip' => '图片大小750×750',
'required' => true, 'required' => true,
'imageCompressEnable' => 1, 'imageCompressEnable' => 1,
'imageCompressBorder' => 750, 'imageCompressBorder' => 750,
]) ?> ]) ?>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label required">冠军级别</label> <label class="layui-form-label required">冠军级别</label>
<div class="layui-input-block" style="width: 200px"> <div class="layui-input-block" style="width: 200px">
<select name="cat_id"> <select name="cat_id">
<option value=""></option> <option value=""></option>
<?php foreach ($cat_list as $key => $val): ?> <?php foreach ($cat_list as $key => $val): ?>
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat_id ? 'selected' : '' ?>><?= $val['name'] ?></option> <option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label required">冠军分类</label> <label class="layui-form-label required">冠军分类</label>
<div class="layui-input-block" style="width: 200px"> <div class="layui-input-block" style="width: 200px">
<select name="cat1_id"> <select name="cat1_id">
<option value=""></option> <option value=""></option>
<?php foreach ($cat_list1 as $key => $val): ?> <?php foreach ($cat_list1 as $key => $val): ?>
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat1_id ? 'selected' : '' ?>><?= $val['name'] ?></option> <option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat1_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label required">签约价格</label> <label class="layui-form-label required">签约价格</label>
<div class="layui-input-block" style="width: 200px"> <div class="layui-input-block" style="width: 200px">
<select name="cat2_id"> <select name="cat2_id">
<option value=""></option> <option value=""></option>
<?php foreach ($cat_list2 as $key => $val): ?> <?php foreach ($cat_list2 as $key => $val): ?>
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat2_id ? 'selected' : '' ?>><?= $val['name'] ?></option> <option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat2_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
</div> </div>
<div class="layui-form-item">
<div class="layui-form-item"> <label class="layui-form-label">排序</label>
<label class="layui-form-label ">多冠组合</label> <div class="layui-input-inline">
<div class="layui-input-block" style="width: 200px"> <input type="number" name="sort" placeholder="请输入数字" autocomplete="off"
<select name="cat3_id"> class="layui-input" value="<?= $model->sort ? $model->sort : 100 ?>">
<option value=""></option> </div>
<?php foreach ($cat_list3 as $key => $val): ?> <div class="layui-form-mid layui-word-aux">降序,值越大排序越靠前</div>
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat3_id ? 'selected' : '' ?>><?= $val['name'] ?></option> </div>
<?php endforeach; ?>
</select>
</div> <div class="layui-form-item">
</div> <label class="layui-form-label required">多冠组合</label>
<div class="layui-input-block" style="width: 200px">
<select name="cat3_id">
<div class="layui-form-item"> <option value=""></option>
<label class="layui-form-label required">交付权益</label> <?php foreach ($cat_list3 as $key => $val): ?>
<div class="layui-input-block" style="width: 200px"> <option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat3_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
<select name="cat4_id"> <?php endforeach; ?>
<option value=""></option> </select>
<?php foreach ($cat_list4 as $key => $val): ?> </div>
<option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat4_id ? 'selected' : '' ?>><?= $val['name'] ?></option> </div>
<?php endforeach; ?>
</select>
</div> <div class="layui-form-item">
</div> <label class="layui-form-label required">交付权益</label>
<div class="layui-input-block" style="width: 200px">
<select name="cat4_id">
<div class="layui-form-item"> <option value=""></option>
<label class="layui-form-label required">出生日期</label> <?php foreach ($cat_list4 as $key => $val): ?>
<div class="layui-input-inline"> <option value="<?= $val['id'] ?>" <?= $val['id'] == $model->goodsCat->cat4_id ? 'selected' : '' ?>><?= $val['name'] ?></option>
<input type="date" name="date" placeholder="请输入出生日期" autocomplete="off" <?php endforeach; ?>
class="layui-input" value="<?= $model->date ?>" lay-verify="required"> </select>
</div> </div>
<div class="layui-form-mid layui-word-aux"></div> </div>
</div>
<div class="layui-form-item">
<div class="layui-form-item"> <label class="layui-form-label required">出生日期</label>
<label class="layui-form-label required">代表奖项</label> <div class="layui-input-inline">
<div class="layui-input-inline"> <input type="text" name="date" class="layui-input" id="test2" placeholder="yyyy">
<input name="subtitle" placeholder="请输入代表奖项" autocomplete="off" </div>
class="layui-input" value="<?= $model->goodsHub->subtitle ?>" <div class="layui-form-mid layui-word-aux"></div>
lay-verify="required"> </div>
</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">
<div class="layui-form-item"> <input name="subtitle" placeholder="请输入代表奖项" autocomplete="off"
<label class="layui-form-label required">签约价格</label> class="layui-input" value="<?= $model->goodsHub->subtitle ?>"
<div class="layui-input-inline"> lay-verify="required">
<input type="number" name="price" placeholder="请输入售价" autocomplete="off" </div>
class="layui-input" value="<?= $model->price ?>" lay-verify="required"> <div class="layui-form-mid layui-word-aux"></div>
</div> </div>
<div class="layui-form-mid layui-word-aux"></div>
</div>
<div class="layui-form-item">
<?= PickFile::widget([ <label class="layui-form-label required">签约价格</label>
'multiple' => true, <div class="layui-input-inline">
'accept' => 'images', <input type="number" name="price" placeholder="请输入售价" autocomplete="off"
'id' => 'pic_urls', class="layui-input" value="<?= $model->price ?>" lay-verify="required">
'name' => 'pic_urls', </div>
'label' => '冠军轮播图(多张)', <div class="layui-form-mid layui-word-aux"></div>
'value' => $model->goodsHub ? $model->goodsHub->pic_urls : '', </div>
'tip' => '图片大小750×750',
'required' => true, <?= PickFile::widget([
// 'imageCompressEnable' => 1, 'multiple' => true,
// 'imageCompressBorder' => 750, 'accept' => 'images',
]) ?> 'id' => 'pic_urls',
'name' => 'pic_urls',
'label' => '冠军轮播图(多张)',
<?= PickFile::widget([ 'value' => $model->goodsHub ? $model->goodsHub->pic_urls : '',
'accept' => 'images', 'tip' => '图片大小750×750',
'id' => 'banner_urls', 'required' => true,
'name' => 'banner_urls', // 'imageCompressEnable' => 1,
'label' => '冠军详情图', // 'imageCompressBorder' => 750,
'value' => $model->goodsHub ? $model->goodsHub->banner_urls : '', ]) ?>
// 'tip' => '图片大小750×750',
'required' => true,
'imageCompressEnable' => 1, <?= PickFile::widget([
'imageCompressBorder' => 750, 'accept' => 'images',
]) ?> 'id' => 'banner_urls',
'name' => 'banner_urls',
'label' => '冠军详情图',
'value' => $model->goodsHub ? $model->goodsHub->banner_urls : '',
// 'tip' => '图片大小750×750',
<?php 'required' => true,
'imageCompressEnable' => 1,
'imageCompressBorder' => 750,
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); <?php
//
$temp_arr[] = [
'name' => $end, if (!empty($model->goodsHub->video_url)) {
'url' => $val, $json_de = json_decode($model->goodsHub->video_url, true);
]; $temp_arr = [];
} foreach ($json_de as $key => $val) {
$model->goodsHub->video_url = json_encode($temp_arr, JSON_UNESCAPED_UNICODE); $explode = explode('/', $val);
} $end = end($explode);
?> //
$temp_arr[] = [
'name' => $end,
<?= PickFile::widget([ 'url' => $val,
'accept' => 'file', ];
'multiple' => true, }
'id' => 'video_url', $model->goodsHub->video_url = json_encode($temp_arr, JSON_UNESCAPED_UNICODE);
'name' => 'video_url', }
'label' => '冠军视频', ?>
'value' => $model->goodsHub ? $model->goodsHub->video_url : '',
'tip' => '视频最大50M',
'required' => false <?= PickFile::widget([
]) ?> 'accept' => 'file',
'multiple' => true,
'id' => 'video_url',
<?= PickFile::widget([ 'name' => 'video_url',
'multiple' => true, 'label' => '冠军视频',
'accept' => 'images', 'value' => $model->goodsHub ? $model->goodsHub->video_url : '',
'id' => 'video_banner_urls', 'tip' => '视频最大50M',
'name' => 'video_banner_urls', 'required' => false
'label' => '冠军视频封面图', ]) ?>
'value' => $model->goodsHub ? $model->goodsHub->video_banner_urls : '',
'tip' => '图片大小750×750',
'required' => true, <?= PickFile::widget([
// 'imageCompressEnable' => 1, 'multiple' => true,
// 'imageCompressBorder' => 750, 'accept' => 'images',
]) ?> 'id' => 'video_banner_urls',
'name' => 'video_banner_urls',
'label' => '冠军视频封面图',
'value' => $model->goodsHub ? $model->goodsHub->video_banner_urls : '',
<div class="layui-form-item"> 'tip' => '图片大小750×750',
<div class="layui-input-block"> 'required' => true,
<div class=""> // 'imageCompressEnable' => 1,
<button class="layui-btn" lay-submit="" lay-filter="layui-form-submit">保存</button> // 'imageCompressBorder' => 750,
</div> ]) ?>
</div>
</div>
</div>
</div> <div class="layui-form-item">
</div> <div class="layui-input-block">
</div> <div class="">
</div> <button class="layui-btn" lay-submit="" lay-filter="layui-form-submit">保存</button>
</div> </div>
<script> </div>
<?php $this->beginBlock('js_script_wrap') ?> </div>
layui.config({ </div>
base: '/statics/layuiadmin/' //静态资源所在路径 </div>
}).extend({ </div>
index: 'lib/index' //主入口模块 </div>
}).use(['index', 'user'], function () { </div>
var $ = layui.$ </div>
, setter = layui.setter <script>
, admin = layui.admin <?php $this->beginBlock('js_script_wrap') ?>
, form = layui.form layui.config({
, router = layui.router() base: '/statics/layuiadmin/' //静态资源所在路径
, search = router.search; }).extend({
index: 'lib/index' //主入口模块
form.render(); }).use(['index', 'user','laydate'], function () {
//提交 var $ = layui.$
var submitLock = false; , setter = layui.setter
form.on('submit(layui-form-submit)', function (obj) { , admin = layui.admin
if (submitLock) { , form = layui.form
return false; , router = layui.router()
} , laydate = layui.laydate
submitLock = true; , search = router.search;
//请求登入接口
//console.log(obj) form.render();
var url = '<?= \Yii::$app->urlManager->createUrl(["/admin/mall/goods/edit", 'id' => $model->id ? $model->id : 0]) ?>'; //年选择器
var returnUrl = "<?= $return_url ?>"; laydate.render({
var data = obj.field; elem: '#test2'
,type: 'year'
var urls = [] ,value: '<?= $model->date ?>'
});
data.video_banner_urls = JSON.stringify(_gallery_video_banner_urls); //提交
var submitLock = false;
form.on('submit(layui-form-submit)', function (obj) {
urls = window._filelist_video_url.map(function (val) { if (submitLock) {
console.log(val) return false;
return val.url }
}) submitLock = true;
//请求登入接口
data.video_url = JSON.stringify(urls); //console.log(obj)
data.pic_urls = JSON.stringify(_gallery_pic_urls); var url = '<?= \Yii::$app->urlManager->createUrl(["/admin/mall/goods/edit", 'id' => $model->id ? $model->id : 0]) ?>';
data._csrf = _csrf; var returnUrl = "<?= $return_url ?>";
var data = obj.field;
console.log(data) var urls = []
$.ajax(url, { data.video_banner_urls = JSON.stringify(_gallery_video_banner_urls);
type: "POST",
dataType: "json",
data: data, urls = window._filelist_video_url.map(function (val) {
timeout: 10000, console.log(val)
success: function (res) { return val.url
if (res.code == 0) { })
layer.msg(res.msg, {
offset: '15px' data.video_url = JSON.stringify(urls);
, icon: 1 data.pic_urls = JSON.stringify(_gallery_pic_urls);
, time: 1000 data._csrf = _csrf;
}, function () {
if (returnUrl) {
location.href = returnUrl; console.log(data)
} else {
location.reload(); $.ajax(url, {
} type: "POST",
}); dataType: "json",
} else { data: data,
layer.msg(res.msg, { timeout: 10000,
offset: '15px' success: function (res) {
, icon: 2 if (res.code == 0) {
, time: 1000 layer.msg(res.msg, {
}, function () { offset: '15px'
}); , icon: 1
} , time: 1000
}, }, function () {
error: function (xhr, type, err) { if (returnUrl) {
layer.msg(xhr.responseText, { location.href = returnUrl;
offset: '15px' } else {
, icon: 2 location.reload();
, time: 1000 }
}, function () { });
}); } else {
}, layer.msg(res.msg, {
complete: function () { offset: '15px'
submitLock = false; , icon: 2
} , time: 1000
}) }, function () {
}); });
}); }
<?php $this->endBlock(); ?> },
</script> error: function (xhr, type, err) {
<?php $this->registerJs($this->blocks['js_script_wrap'], \yii\web\View::POS_END); ?> 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

View File

@ -75,6 +75,13 @@ $this->params['breadcrumbs'][] = $this->title;
</div> </div>
</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"> <div class="layui-form-item" style="display: block">
<label class="layui-form-label required">案例状态</label> <label class="layui-form-label required">案例状态</label>

View File

@ -143,11 +143,11 @@ $user_type = \Yii::$app->request->get('user_type');
, {field: 'id', title: 'ID', width: 80} , {field: 'id', title: 'ID', width: 80}
, {field: 'goods_name', title: '冠军名称'} , {field: 'goods_name', title: '冠军名称'}
, {field: 'bj_name', title: '所属分类'} , {field: 'bj_name', title: '所属分类'}
// , {field: 'money', title: '案例金额'}
// , {field: 'device', title: '案例设备'} // , {field: 'device', title: '案例设备'}
// , {field: 'business', title: '营业时间', width: 110} // , {field: 'business', title: '营业时间', width: 110}
, {field: 'status', title: '状态', templet: '#statusTpl', width: 80} , {field: 'status', title: '状态', templet: '#statusTpl', width: 80}
, {field: 'created_at_cn', title: '创建时间', width: 150} , {field: 'created_at_cn', title: '创建时间', width: 150}
, {field: 'sort', title: '案例排序'}
, {title: '操作', fixed: 'right', toolbar: '#rowBarTpl', width: 200} , {title: '操作', fixed: 'right', toolbar: '#rowBarTpl', width: 200}
] ]
] ]

View File

@ -78,7 +78,7 @@ class GoodsController extends Controller
$data = $form->search(); $data = $form->search();
foreach ($data['data'] as $key => $value) { 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]['video_url'] = SiteHelper::getFullUrl($value['video_url']);
$data['data'][$key]['pic_arr'] = []; $data['data'][$key]['pic_arr'] = [];
if ($value['pic_urls'] != null) { if ($value['pic_urls'] != null) {
@ -141,7 +141,7 @@ class GoodsController extends Controller
$data = $form->search(); $data = $form->search();
foreach ($data['data'] as $key => $value) { 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'] = []; $data['data'][$key]['pic_arr'] = [];
if ($value['pic_urls'] != null) { if ($value['pic_urls'] != null) {
$pic_arr = json_decode($value['pic_urls'], true); $pic_arr = json_decode($value['pic_urls'], true);

View File

@ -71,7 +71,7 @@ class BoxForm extends ApiModel
$count = $query->count(); $count = $query->count();
$pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $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) { foreach ($list as $index => $item) {
// $item['business'] = $item['begin_time'] . '-' . $item['end_time']; // $item['business'] = $item['begin_time'] . '-' . $item['end_time'];
$list[$index]['created_at_cn'] = date("Y-m-d H:i", $item['created_at']); $list[$index]['created_at_cn'] = date("Y-m-d H:i", $item['created_at']);

File diff suppressed because it is too large Load Diff

Binary file not shown.