vr-shopxo-source/application/admin/form/Goods.php

333 lines
13 KiB
PHP
Raw Normal View History

2020-05-20 10:32:23 +00:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
2020-05-20 10:32:23 +00:00
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Licensed ( https://opensource.org/licenses/mit-license.php )
2020-05-20 10:32:23 +00:00
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
2020-06-02 15:32:29 +00:00
namespace app\admin\form;
2020-05-20 10:32:23 +00:00
use think\Db;
2020-05-31 14:06:40 +00:00
use app\service\GoodsService;
use app\service\RegionService;
use app\service\BrandService;
2020-05-20 10:32:23 +00:00
/**
2020-06-08 06:03:33 +00:00
* 商品动态表格
2020-05-20 10:32:23 +00:00
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-05-16
* @desc description
*/
2020-06-02 15:32:29 +00:00
class Goods
2020-05-20 10:32:23 +00:00
{
2020-06-05 15:29:04 +00:00
// 基础条件
public $condition_base = [
['is_delete_time', '=', 0],
];
2020-05-20 10:32:23 +00:00
/**
2020-06-02 15:32:29 +00:00
* 入口
2020-05-20 10:32:23 +00:00
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-05-16
* @desc description
* @param [array] $params [输入参数]
*/
2020-06-02 15:32:29 +00:00
public function Run($params = [])
2020-05-20 10:32:23 +00:00
{
2020-05-29 06:03:53 +00:00
return [
// 基础配置
'base' => [
'key_field' => 'id',
'status_field' => 'is_shelves',
2020-05-31 14:06:40 +00:00
'is_search' => 1,
2020-06-02 15:32:29 +00:00
'search_url' => MyUrl('admin/goods/index'),
2020-06-07 09:36:43 +00:00
'is_delete' => 1,
'delete_url' => MyUrl('admin/goods/delete'),
'delete_key' => 'ids',
'detail_title' => '基础信息',
2020-05-29 06:03:53 +00:00
],
// 表单配置
'form' => [
2020-06-05 15:29:04 +00:00
[
'view_type' => 'checkbox',
'is_checked' => 0,
'checked_text' => '反选',
'not_checked_text' => '全选',
'align' => 'center',
'width' => 80,
],
2020-05-29 06:03:53 +00:00
[
'label' => '商品ID',
'view_type' => 'field',
'view_key' => 'id',
2020-06-07 17:14:42 +00:00
'width' => 105,
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-06-05 15:29:04 +00:00
'search_config' => [
'form_type' => 'input',
'where_type' => '=',
],
2020-05-29 06:03:53 +00:00
],
[
'label' => '商品信息',
'view_type' => 'module',
'view_key' => 'goods/module/info',
'grid_size' => 'lg',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
'sort_field' => 'title',
2020-05-31 14:06:40 +00:00
'search_config' => [
'form_type' => 'input',
'form_name' => 'title|simple_desc|seo_title|seo_keywords|seo_keywords',
2020-06-02 15:32:29 +00:00
'where_type' => 'like',
2020-06-05 15:29:04 +00:00
'placeholder' => '请输入商品名称/简述/SEO信息'
2020-07-02 14:42:01 +00:00
],
],
[
2020-07-29 07:54:38 +00:00
'label' => '商品分类',
2020-07-02 14:42:01 +00:00
'view_type' => 'field',
2020-07-29 07:54:38 +00:00
'view_key' => 'category_text',
2020-07-02 14:42:01 +00:00
'search_config' => [
2020-07-29 07:54:38 +00:00
'form_type' => 'module',
'template' => 'lib/module/goods_category',
'form_name' => 'id',
'where_type' => 'in',
2020-08-20 15:38:41 +00:00
'where_value_custom' => 'WhereValueGoodsCategory',
2020-07-29 07:54:38 +00:00
'data' => GoodsService::GoodsCategoryAll(),
],
],
[
'label' => '品牌',
'view_type' => 'field',
'view_key' => 'brand_name',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-07-29 07:54:38 +00:00
'search_config' => [
'form_type' => 'module',
'template' => 'lib/module/category_brand',
'form_name' => 'brand_id',
'data' => BrandService::CategoryBrand(),
'data_key' => 'id',
2020-07-02 14:42:01 +00:00
'data_name' => 'name',
2020-07-29 07:54:38 +00:00
'where_type' => 'in',
2020-05-31 14:06:40 +00:00
],
2020-05-29 06:03:53 +00:00
],
[
'label' => '销售价格(元)',
'view_type' => 'field',
'view_key' => 'price',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-05-31 14:06:40 +00:00
'search_config' => [
'form_type' => 'section',
'form_name' => 'min_price',
2020-06-02 15:32:29 +00:00
'is_point' => 1,
2020-05-31 14:06:40 +00:00
],
2020-05-29 06:03:53 +00:00
],
[
'label' => '原价(元)',
'view_type' => 'field',
'view_key' => 'original_price',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-05-31 14:06:40 +00:00
'search_config' => [
'form_type' => 'section',
2020-06-02 15:32:29 +00:00
'form_name' => 'min_original_price',
'is_point' => 1,
2020-05-31 14:06:40 +00:00
],
2020-05-29 06:03:53 +00:00
],
[
'label' => '库存总量',
2020-05-29 06:03:53 +00:00
'view_type' => 'field',
'view_key' => ['inventory', 'inventory_unit'],
'view_key_join' => ' ',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-05-31 14:06:40 +00:00
'search_config' => [
'form_type' => 'section',
'form_name' => 'inventory',
],
2020-05-29 06:03:53 +00:00
],
[
'label' => '上下架',
'view_type' => 'status',
'view_key' => 'is_shelves',
'post_url' => MyUrl('admin/goods/statusupdate'),
2020-05-29 06:03:53 +00:00
'is_form_su' => 1,
'align' => 'center',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-05-31 14:06:40 +00:00
'search_config' => [
'form_type' => 'select',
2020-06-02 15:32:29 +00:00
'where_type' => 'in',
2020-05-31 14:06:40 +00:00
'data' => lang('common_is_shelves_list'),
'data_key' => 'id',
'data_name' => 'name',
'is_multiple' => 1,
],
2020-05-29 06:03:53 +00:00
],
[
'label' => '扣减库存',
'view_type' => 'status',
'view_key' => 'is_deduction_inventory',
'post_url' => MyUrl('admin/goods/statusupdate'),
2020-05-29 06:03:53 +00:00
'align' => 'center',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-05-31 14:06:40 +00:00
'search_config' => [
'form_type' => 'select',
2020-06-02 15:32:29 +00:00
'where_type' => 'in',
2020-05-31 14:06:40 +00:00
'data' => lang('common_is_text_list'),
'data_key' => 'id',
'data_name' => 'name',
'is_multiple' => 1,
],
2020-05-29 06:03:53 +00:00
],
[
2020-07-29 07:54:38 +00:00
'label' => '商品类型',
2020-05-31 14:06:40 +00:00
'view_type' => 'field',
2020-07-29 07:54:38 +00:00
'view_key' => 'site_type',
'view_data_key' => 'name',
'view_data' => lang('common_site_type_list'),
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-05-31 14:06:40 +00:00
'search_config' => [
2020-07-29 07:54:38 +00:00
'form_type' => 'select',
'where_type' => 'in',
'data' => lang('common_site_type_list'),
'data_key' => 'value',
'data_name' => 'name',
'is_multiple' => 1,
2020-05-31 14:06:40 +00:00
],
2020-05-29 06:03:53 +00:00
],
[
2020-07-29 07:54:38 +00:00
'label' => '商品型号',
2020-05-29 06:03:53 +00:00
'view_type' => 'field',
2020-07-29 07:54:38 +00:00
'view_key' => 'model',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-05-31 14:06:40 +00:00
'search_config' => [
2020-07-29 07:54:38 +00:00
'form_type' => 'input',
'where_type' => 'like',
2020-05-31 14:06:40 +00:00
],
],
2020-06-07 09:36:43 +00:00
[
'label' => '生产地',
'view_type' => 'field',
'view_key' => 'place_origin_name',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-06-07 09:36:43 +00:00
'search_config' => [
'form_type' => 'select',
'form_name' => 'place_origin',
'data' => RegionService::RegionItems(['pid'=>0]),
'data_key' => 'id',
'data_name' => 'name',
'where_type' => 'in',
'is_multiple' => 1,
],
],
2020-06-28 14:50:10 +00:00
[
'label' => '购买赠送积分比例',
'view_type' => 'field',
'view_key' => 'give_integral',
'view_join_last'=> '%',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-06-28 14:50:10 +00:00
'search_config' => [
'form_type' => 'section',
],
],
[
'label' => '单次最低起购数量',
'view_type' => 'field',
'view_key' => 'buy_min_number',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
'search_config' => [
'form_type' => 'section',
],
],
[
'label' => '单次最大购买数量',
'view_type' => 'field',
'view_key' => 'buy_max_number',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
'search_config' => [
'form_type' => 'section',
],
],
2021-01-27 14:21:04 +00:00
[
'label' => '销量',
'view_type' => 'field',
'view_key' => 'sales_count',
'is_sort' => 1,
'search_config' => [
'form_type' => 'section',
],
],
[
'label' => '访问次数',
'view_type' => 'field',
'view_key' => 'access_count',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
'search_config' => [
'form_type' => 'section',
],
],
2020-05-31 14:06:40 +00:00
[
'label' => '创建时间',
'view_type' => 'field',
'view_key' => 'add_time',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-05-31 14:06:40 +00:00
'search_config' => [
'form_type' => 'datetime',
2020-06-08 06:03:33 +00:00
],
],
[
'label' => '更新时间',
'view_type' => 'field',
'view_key' => 'upd_time',
2020-10-24 16:45:09 +00:00
'is_sort' => 1,
2020-06-08 06:03:33 +00:00
'search_config' => [
'form_type' => 'datetime',
2020-05-31 14:06:40 +00:00
],
2020-05-29 06:03:53 +00:00
],
[
'label' => '操作',
'view_type' => 'operate',
'view_key' => 'goods/module/operate',
'align' => 'center',
'fixed' => 'right',
],
2020-05-20 10:32:23 +00:00
],
];
}
2020-06-05 15:29:04 +00:00
/**
* 商品分类条件处理
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-06-03
* @desc description
2020-06-08 06:03:33 +00:00
* @param [array] $value [条件值]
2020-06-05 15:29:04 +00:00
* @param [array] $params [输入参数]
*/
public function WhereValueGoodsCategory($value, $params = [])
{
if(!empty($value))
{
// 是否为数组
if(!is_array($value))
{
$value = [$value];
}
// 获取分类下的所有分类 id
2020-06-08 06:03:33 +00:00
$cids = GoodsService::GoodsCategoryItemsIds($value, 1);
2020-06-05 15:29:04 +00:00
// 获取商品 id
2020-06-08 06:03:33 +00:00
$ids = Db::name('GoodsCategoryJoin')->where(['category_id'=>$cids])->column('goods_id');
2020-06-05 15:29:04 +00:00
// 避免空条件造成无效的错觉
2020-06-08 06:03:33 +00:00
return empty($ids) ? [0] : $ids;
2020-06-05 15:29:04 +00:00
}
return $value;
}
2020-06-08 06:03:33 +00:00
}
?>