Goods.php 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy riht 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shop\controller;
  11. use addon\form\model\Form;
  12. use addon\postertemplate\model\PosterTemplate as PosterTemplateModel;
  13. use app\model\express\Config as ExpressConfig;
  14. use app\model\express\ExpressTemplate as ExpressTemplateModel;
  15. use app\model\goods\Batch;
  16. use app\model\goods\Goods as GoodsModel;
  17. use app\model\goods\GoodsAttribute as GoodsAttributeModel;
  18. use app\model\goods\GoodsBrand as GoodsBrandModel;
  19. use app\model\goods\GoodsBrowse;
  20. use app\model\goods\GoodsCategory as GoodsCategoryModel;
  21. use app\model\goods\GoodsCollect;
  22. use app\model\goods\GoodsEvaluate as GoodsEvaluateModel;
  23. use app\model\goods\GoodsExport;
  24. use app\model\goods\GoodsImport;
  25. use app\model\goods\GoodsLabel as GoodsLabelModel;
  26. use app\model\goods\GoodsPoster;
  27. use app\model\goods\GoodsService as GoodsServiceModel;
  28. use app\model\store\Store as StoreModel;
  29. use app\model\web\Config;
  30. use app\model\web\Config as ConfigModel;
  31. /**
  32. * 实物商品
  33. * Class Goods
  34. * @package app\shop\controller
  35. */
  36. class Goods extends BaseShop
  37. {
  38. public function __construct()
  39. {
  40. $this->app_module = input('app_module', SHOP_MODULE);
  41. if ($this->app_module == 'store') {
  42. $this->initConstructInfo(); // 加载构造函数重要信息
  43. } else {
  44. parent::__construct();
  45. }
  46. }
  47. /**
  48. * 商品列表
  49. * @return mixed
  50. */
  51. public function lists()
  52. {
  53. $stockalarm = input('stockalarm', 0);
  54. $goods_model = new GoodsModel();
  55. if (request()->isAjax()) {
  56. $page_index = input('page', 1);
  57. $page_index = intval($page_index);
  58. $page_size = input('page_size', PAGE_LIST_ROWS);
  59. $search_text = input('search_text', "");
  60. $goods_state = input('goods_state', "");
  61. $start_sale = input('start_sale', 0);
  62. $end_sale = input('end_sale', 0);
  63. $start_price = input('start_price', 0);
  64. $end_price = input('end_price', 0);
  65. $sku_start_price = input('sku_start_price', 0);
  66. $sku_end_price = input('sku_end_price', 0);
  67. $goods_class = input('goods_class', "");
  68. $label_id = input('label_id', "");
  69. $brand_id = input('brand_id', "");
  70. $order = input('order', '');
  71. $sort = input('sort', 'asc');
  72. $sku_no = input('sku_no', '');
  73. $promotion_type = input('promotion_type', "");
  74. $category_id = input('category_id', "");
  75. $condition = [
  76. [ 'is_delete', '=', 0 ],
  77. [ 'site_id', '=', $this->site_id ],
  78. ];
  79. if (!empty($search_text)) {
  80. $condition[] = [ 'goods_name', 'like', '%' . $search_text . '%' ];
  81. }
  82. if (!empty($category_id)) {
  83. $condition[] = [ 'category_id', 'like', '%,' . $category_id . ',%' ];
  84. }
  85. if ($goods_class !== "") {
  86. $condition[] = [ 'goods_class', '=', $goods_class ];
  87. }
  88. if (!empty($label_id)) {
  89. $condition[] = [ 'label_id', '=', $label_id ];
  90. }
  91. if (!empty($brand_id)) {
  92. $condition[] = [ 'brand_id', '=', $brand_id ];
  93. }
  94. if (!empty($promotion_type)) {
  95. $condition[] = [ 'promotion_addon', 'like', "%{$promotion_type}%" ];
  96. }
  97. // 上架状态
  98. if ($goods_state !== '') {
  99. $condition[] = [ 'goods_state', '=', $goods_state ];
  100. }
  101. if (!empty($start_sale)) $condition[] = [ 'sale_num', '>=', $start_sale ];
  102. if (!empty($end_sale)) $condition[] = [ 'sale_num', '<=', $end_sale ];
  103. if (!empty($start_price)) $condition[] = [ 'price', '>=', $start_price ];
  104. if (!empty($end_price)) $condition[] = [ 'price', '<=', $end_price ];
  105. if (!empty($sku_start_price)) $condition[] = [ 'sku.price', '>=', $sku_start_price ];
  106. if (!empty($sku_end_price)) $condition[] = [ 'sku.price', '<=', $sku_end_price ];
  107. // 查询库存预警的商品
  108. if ($stockalarm) {
  109. $stock_alarm = $goods_model->getGoodsStockAlarm($this->site_id);
  110. if (!empty($stock_alarm[ 'data' ])) {
  111. $condition[] = [ 'goods_id', 'in', $stock_alarm[ 'data' ] ];
  112. } else {
  113. return success(0, '', [ 'page_count' => 1, 'count' => 0, 'list' => [] ]);
  114. }
  115. }
  116. if (!empty($sku_no)) {
  117. $goods_sku_list = $goods_model->getGoodsSkuList([ [ 'sku_no', 'like', '%' . $sku_no . '%' ] ], 'goods_id')[ 'data' ];
  118. $goods_id_arr = array_unique(array_column($goods_sku_list, 'goods_id'));
  119. $condition[] = [ 'goods_id', 'in', $goods_id_arr ];
  120. }
  121. $order_by = 'create_time desc';
  122. if ($order != '') {
  123. if ($order == 'sort') {
  124. $order_by = $order . ' ' . $sort . ',create_time desc';
  125. } else {
  126. $order_by = $order . ' ' . $sort;
  127. }
  128. }
  129. $field = 'goods_id,goods_name,site_id,site_name,goods_image,goods_state,price,goods_stock,goods_stock_alarm,create_time,sale_num,is_virtual,goods_class,goods_class_name,is_fenxiao,fenxiao_type,promotion_addon,sku_id,is_consume_discount,discount_config,discount_method,sort,label_id,is_delete,label_name,virtual_deliver_type';
  130. $res = $goods_model->getGoodsPageList($condition, $page_index, $page_size, $order_by, $field);
  131. $goods_promotion_type = event('GoodsPromotionType');
  132. if (!empty($res[ 'data' ][ 'list' ])) {
  133. foreach ($res[ 'data' ][ 'list' ] as $k => &$v) {
  134. if (!empty($v[ 'promotion_addon' ])) {
  135. $v[ 'promotion_addon' ] = json_decode($v[ 'promotion_addon' ], true);
  136. foreach ($v[ 'promotion_addon' ] as $ck => $cv) {
  137. foreach ($goods_promotion_type as $gk => $gv) {
  138. if ($gv[ 'type' ] == $ck) {
  139. $res[ 'data' ][ 'list' ][ $k ][ 'promotion_addon_list' ][] = $gv;
  140. break;
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. return $res;
  148. } else {
  149. $goods_state = input('state', '');
  150. $this->assign('goods_state', $goods_state);
  151. //获取一级商品分类
  152. $goods_category_model = new GoodsCategoryModel();
  153. $condition = [
  154. [ 'pid', '=', 0 ],
  155. [ 'site_id', '=', $this->site_id ]
  156. ];
  157. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate')[ 'data' ];
  158. $this->assign("goods_category_list", $goods_category_list);
  159. // 商品分组
  160. $goods_label_model = new GoodsLabelModel();
  161. $label_list = $goods_label_model->getLabelList([ [ 'site_id', '=', $this->site_id ] ], 'id,label_name', 'sort asc')[ 'data' ];
  162. $this->assign("label_list", $label_list);
  163. // 商品品牌
  164. $goods_brand_model = new GoodsBrandModel();
  165. $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', '=', $this->site_id ] ], 'brand_id,brand_name', 'sort asc')[ 'data' ];
  166. $this->assign("brand_list", $brand_list);
  167. // 商品服务
  168. $goods_service_model = new GoodsServiceModel();
  169. $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
  170. $this->assign("service_list", $service_list);
  171. //获取运费模板
  172. $express_template_model = new ExpressTemplateModel();
  173. $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc')[ 'data' ];
  174. $this->assign("express_template_list", $express_template_list);
  175. //判断会员价插件
  176. $memberprice_is_exit = addon_is_exit('memberprice', $this->site_id);
  177. $this->assign('memberprice_is_exit', $memberprice_is_exit);
  178. // 获取商品排序
  179. $confif_model = new ConfigModel();
  180. $goods_sort = $confif_model->getGoodsSort($this->site_id);
  181. $this->assign("goods_sort", $goods_sort[ 'data' ][ 'value' ][ 'type' ]);
  182. // 营销活动
  183. $goods_promotion_type = event('GoodsPromotionType');
  184. $this->assign('promotion_type', $goods_promotion_type);
  185. $this->assign('virtualcard_exit', addon_is_exit('virtualcard', $this->site_id));
  186. $this->assign('stockalarm', $stockalarm);
  187. $this->assign('pc_domain', '');
  188. if (addon_is_exit('pc')) {
  189. $config_model = new Config();
  190. $config = $config_model->getPcDomainName($this->site_id);
  191. $this->assign('pc_domain', $config[ 'data' ][ 'value' ][ 'domain_name_pc' ] ?? '');
  192. }
  193. $this->assign('goods_class', array_column(event('GoodsClass'), null, 'goods_class'));
  194. $cardservice_is_exit = addon_is_exit('cardservice', $this->site_id);
  195. $this->assign('cardservice_is_exit', $cardservice_is_exit);
  196. $form_is_exit = addon_is_exit('form', $this->site_id);
  197. if ($form_is_exit) {
  198. $form_list = ( new Form() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', 'goods' ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name')[ 'data' ];
  199. $this->assign('form_list', $form_list);
  200. }
  201. $this->assign('form_is_exit', $form_is_exit);
  202. return $this->fetch("goods/lists");
  203. }
  204. }
  205. /**
  206. * 修改商品排序
  207. */
  208. public function modifySort()
  209. {
  210. if (request()->isAjax()) {
  211. $goods_model = new GoodsModel();
  212. $goods_id = input('goods_id', 0);
  213. $sort = input('sort', 0);
  214. return $goods_model->modifyGoodsSort($sort, $goods_id, $this->site_id);
  215. }
  216. }
  217. /**
  218. * 添加商品
  219. * @return mixed
  220. */
  221. public function addGoods()
  222. {
  223. if (request()->isAjax()) {
  224. $category_id = input("category_id", 0);// 分类id
  225. $category_json = json_encode($category_id);//分类字符串
  226. $category_id = ',' . implode(',', $category_id) . ',';
  227. $data = [
  228. 'goods_name' => input("goods_name", ""),// 商品名称,
  229. 'goods_attr_class' => input("goods_attr_class", ""),// 商品类型id,
  230. 'goods_attr_name' => input("goods_attr_name", ""),// 商品类型名称,
  231. 'is_limit' => input("is_limit", "0"),// 商品是否限购,
  232. 'limit_type' => input("limit_type", "1"),// 商品限购类型,
  233. 'site_id' => $this->site_id,
  234. 'category_id' => $category_id,
  235. 'category_json' => $category_json,
  236. 'goods_image' => input("goods_image", ""),// 商品主图路径
  237. 'goods_content' => input("goods_content", ""),// 商品详情
  238. 'goods_state' => input("goods_state", ""),// 商品状态(1.正常0下架)
  239. 'price' => input("price", 0),// 商品价格(取第一个sku)
  240. 'market_price' => input("market_price", 0),// 市场价格(取第一个sku)
  241. 'cost_price' => input("cost_price", 0),// 成本价(取第一个sku)
  242. 'sku_no' => input("sku_no", ""),// 商品sku编码
  243. 'weight' => input("weight", ""),// 重量
  244. 'volume' => input("volume", ""),// 体积
  245. 'goods_stock' => input("goods_stock", 0),// 商品库存(总和)
  246. 'goods_stock_alarm' => input("goods_stock_alarm", 0),// 库存预警
  247. 'is_free_shipping' => input("is_free_shipping", 1),// 是否免邮
  248. 'shipping_template' => input("shipping_template", 0),// 指定运费模板
  249. 'goods_spec_format' => input("goods_spec_format", ""),// 商品规格格式
  250. 'goods_attr_format' => input("goods_attr_format", ""),// 商品参数格式
  251. 'introduction' => input("introduction", ""),// 促销语
  252. 'keywords' => input("keywords", ""),// 关键词
  253. 'unit' => input("unit", ""),// 单位
  254. 'sort' => input("sort", 0),// 排序,
  255. 'video_url' => input("video_url", ""),// 视频
  256. 'goods_sku_data' => input("goods_sku_data", ""),// SKU商品数据
  257. 'goods_service_ids' => input("goods_service_ids", ''),// 商品服务id集合
  258. 'label_id' => input("label_id", ''),// 商品分组id
  259. 'brand_id' => input("brand_id", 0),//品牌id
  260. 'virtual_sale' => input("virtual_sale", 0),// 虚拟销量
  261. 'max_buy' => input("max_buy", 0),// 限购
  262. 'min_buy' => input("min_buy", 0),// 起售
  263. 'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐
  264. 'timer_on' => strtotime(input('timer_on', 0)),//定时上架
  265. 'timer_off' => strtotime(input('timer_off', 0)),//定时下架
  266. 'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣
  267. 'qr_id' => input('qr_id', 0),//社群二维码id
  268. 'sale_show' => input('sale_show', 0),//
  269. 'stock_show' => input('stock_show', 0),//
  270. 'market_price_show' => input('market_price_show', 0),//
  271. 'barrage_show' => input('barrage_show', 0),//
  272. 'template_id' => input('template_id', 0),//商品海报id
  273. 'form_id' => input('form_id', 0),
  274. 'support_trade_type' => input('support_trade_type', ''),
  275. 'sale_channel' => input('sale_channel', 'all'),
  276. 'sale_store' => input('sale_store', 'all'),
  277. 'is_unify_price' => input('is_unify_price', '1'),
  278. ];
  279. $goods_model = new GoodsModel();
  280. $res = $goods_model->addGoods($data);
  281. return $res;
  282. } else {
  283. //获取一级商品分类
  284. $goods_category_model = new GoodsCategoryModel();
  285. $condition = [
  286. [ 'pid', '=', 0 ],
  287. [ 'site_id', '=', $this->site_id ]
  288. ];
  289. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate')[ 'data' ];
  290. $this->assign("goods_category_list", $goods_category_list);
  291. //获取运费模板
  292. $express_template_model = new ExpressTemplateModel();
  293. $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc')[ 'data' ];
  294. $this->assign("express_template_list", $express_template_list);
  295. //获取商品类型
  296. $goods_attr_model = new GoodsAttributeModel();
  297. $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', '=', $this->site_id ] ], 'class_id,class_name')[ 'data' ];
  298. $this->assign("attr_class_list", $attr_class_list);
  299. // 商品服务
  300. $goods_service_model = new GoodsServiceModel();
  301. $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
  302. $this->assign("service_list", $service_list);
  303. // 商品分组
  304. $goods_label_model = new GoodsLabelModel();
  305. $label_list = $goods_label_model->getLabelList([ [ 'site_id', '=', $this->site_id ] ], 'id,label_name', 'sort asc')[ 'data' ];
  306. $this->assign("label_list", $label_list);
  307. //商品默认排序值
  308. $config_model = new ConfigModel();
  309. $sort_config = $config_model->getGoodsSort($this->site_id, $this->app_module);
  310. $sort_config = $sort_config[ 'data' ][ 'value' ];
  311. $this->assign("sort_config", $sort_config);
  312. //获取品牌
  313. $goods_brand_model = new GoodsBrandModel();
  314. $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', '=', $this->site_id ] ], "brand_id, brand_name")[ 'data' ];
  315. $this->assign("brand_list", $brand_list);
  316. //获取商品海报
  317. $poster_template_model = new PosterTemplateModel();
  318. $poster_list = $poster_template_model->getPosterTemplateList([ [ 'site_id', '=', $this->site_id ], [ 'template_status', '=', 1 ] ], 'template_id,poster_name,site_id');
  319. $this->assign('poster_list', $poster_list[ 'data' ]);
  320. $this->assign('virtualcard_exit', addon_is_exit('virtualcard', $this->site_id));
  321. $form_is_exit = addon_is_exit('form', $this->site_id);
  322. if ($form_is_exit) {
  323. $form_list = ( new Form() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', 'goods' ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name')[ 'data' ];
  324. $this->assign('form_list', $form_list);
  325. }
  326. $this->assign('form_is_exit', $form_is_exit);
  327. $express_type = ( new ExpressConfig() )->getEnabledExpressType($this->site_id);
  328. $this->assign('express_type', $express_type);
  329. $this->assign('all_goodsclass', event('GoodsClass'));
  330. $this->assign('goods_class', ( new GoodsModel() )->getGoodsClass());
  331. $this->assign('store_is_exit', addon_is_exit('store', $this->site_id));
  332. return $this->fetch("goods/add_goods");
  333. }
  334. }
  335. /**
  336. * 编辑商品
  337. * @return mixed
  338. */
  339. public function editGoods()
  340. {
  341. $goods_model = new GoodsModel();
  342. if (request()->isAjax()) {
  343. $category_id = input("category_id", 0);// 分类id
  344. $category_json = json_encode($category_id);//分类字符串
  345. $category_id = ',' . implode(',', $category_id) . ',';
  346. $data = [
  347. 'goods_id' => input("goods_id", 0),// 商品id
  348. 'goods_name' => input("goods_name", ""),// 商品名称,
  349. 'goods_attr_class' => input("goods_attr_class", ""),// 商品类型id,
  350. 'goods_attr_name' => input("goods_attr_name", ""),// 商品类型名称,
  351. 'is_limit' => input("is_limit", "0"),// 商品是否限购,
  352. 'limit_type' => input("limit_type", "1"),// 商品限购类型,
  353. 'site_id' => $this->site_id,
  354. 'category_id' => $category_id,
  355. 'category_json' => $category_json,
  356. 'goods_image' => input("goods_image", ""),// 商品主图路径
  357. 'goods_content' => input("goods_content", ""),// 商品详情
  358. 'goods_state' => input("goods_state", ""),// 商品状态(1.正常0下架)
  359. 'price' => input("price", 0),// 商品价格(取第一个sku)
  360. 'market_price' => input("market_price", 0),// 市场价格(取第一个sku)
  361. 'cost_price' => input("cost_price", 0),// 成本价(取第一个sku)
  362. 'sku_no' => input("sku_no", ""),// 商品sku编码
  363. 'weight' => input("weight", ""),// 重量
  364. 'volume' => input("volume", ""),// 体积
  365. 'goods_stock' => input("goods_stock", 0),// 商品库存(总和)
  366. 'goods_stock_alarm' => input("goods_stock_alarm", 0),// 库存预警
  367. 'is_free_shipping' => input("is_free_shipping", 1),// 是否免邮
  368. 'shipping_template' => input("shipping_template", 0),// 指定运费模板
  369. 'goods_spec_format' => input("goods_spec_format", ""),// 商品规格格式
  370. 'goods_attr_format' => input("goods_attr_format", ""),// 商品参数格式
  371. 'introduction' => input("introduction", ""),// 促销语
  372. 'keywords' => input("keywords", ""),// 关键词
  373. 'unit' => input("unit", ""),// 单位
  374. 'sort' => input("sort", 0),// 排序,
  375. 'video_url' => input("video_url", ""),// 视频
  376. 'goods_sku_data' => input("goods_sku_data", ""),// SKU商品数据
  377. 'goods_service_ids' => input("goods_service_ids", ''),// 商品服务id集合
  378. 'label_id' => input("label_id", ''),// 商品分组id
  379. 'brand_id' => input("brand_id", 0),//品牌id
  380. 'virtual_sale' => input("virtual_sale", 0),// 虚拟销量
  381. 'max_buy' => input("max_buy", 0),// 限购
  382. 'min_buy' => input("min_buy", 0),// 起售
  383. 'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐
  384. 'timer_on' => strtotime(input('timer_on', 0)),//定时上架
  385. 'timer_off' => strtotime(input('timer_off', 0)),//定时下架
  386. 'spec_type_status' => input('spec_type_status', 0),
  387. 'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣
  388. 'qr_id' => input('qr_id', 0),//社群二维码id
  389. 'sale_show' => input('sale_show', 0),//
  390. 'stock_show' => input('stock_show', 0),//
  391. 'market_price_show' => input('market_price_show', 0),//
  392. 'barrage_show' => input('barrage_show', 0),//
  393. 'template_id' => input('template_id', 0),//商品海报id
  394. 'form_id' => input('form_id', 0),
  395. 'support_trade_type' => input('support_trade_type', ''),
  396. 'sale_channel' => input('sale_channel', 'all'),
  397. 'sale_store' => input('sale_store', 'all'),
  398. 'is_unify_price' => input('is_unify_price', '1'),
  399. ];
  400. $res = $goods_model->editGoods($data);
  401. return $res;
  402. } else {
  403. $goods_id = input("goods_id", 0);
  404. $goods_info = $goods_model->editGetGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ];
  405. if (empty($goods_info)) $this->error('未获取到商品数据', addon_url('shop/goods/lists'));
  406. $goods_sku_list = $goods_model->getGoodsSkuList([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], "sku_id,sku_name,sku_no,sku_spec_format,price,market_price,cost_price,stock,weight,volume,sku_image,sku_images,goods_spec_format,spec_name,stock_alarm,is_default", '')[ 'data' ];
  407. $goods_info[ 'sku_list' ] = $goods_sku_list;
  408. $this->assign("goods_info", $goods_info);
  409. //获取一级商品分类
  410. $goods_category_model = new GoodsCategoryModel();
  411. $condition = [
  412. [ 'pid', '=', 0 ],
  413. [ 'site_id', '=', $this->site_id ]
  414. ];
  415. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate')[ 'data' ];
  416. $this->assign("goods_category_list", $goods_category_list);
  417. //获取运费模板
  418. $express_template_model = new ExpressTemplateModel();
  419. $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc')[ 'data' ];
  420. $this->assign("express_template_list", $express_template_list);
  421. //获取商品类型
  422. $goods_attr_model = new GoodsAttributeModel();
  423. $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', '=', $this->site_id ] ], 'class_id,class_name')[ 'data' ];
  424. $this->assign("attr_class_list", $attr_class_list);
  425. //获取品牌
  426. $goods_brand_model = new GoodsBrandModel();
  427. $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', '=', $this->site_id ] ], "brand_id, brand_name")[ 'data' ];
  428. $this->assign("brand_list", $brand_list);
  429. // 商品服务
  430. $goods_service_model = new GoodsServiceModel();
  431. $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
  432. $this->assign("service_list", $service_list);
  433. // 商品分组
  434. $goods_label_model = new GoodsLabelModel();
  435. $label_list = $goods_label_model->getLabelList([ [ 'site_id', '=', $this->site_id ] ], 'id,label_name', 'sort asc')[ 'data' ];
  436. $this->assign("label_list", $label_list);
  437. //获取商品海报
  438. $poster_template_model = new PosterTemplateModel();
  439. $poster_list = $poster_template_model->getPosterTemplateList([ [ 'site_id', '=', $this->site_id ], [ 'template_status', '=', 1 ], [ 'template_type', '=', 'goods' ] ], 'template_id,poster_name,site_id')[ 'data' ];
  440. $this->assign('poster_list', $poster_list);
  441. $form_is_exit = addon_is_exit('form', $this->site_id);
  442. if ($form_is_exit) {
  443. $form_list = ( new Form() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', 'goods' ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name')[ 'data' ];
  444. $this->assign('form_list', $form_list);
  445. }
  446. $this->assign('form_is_exit', $form_is_exit);
  447. $express_type = ( new ExpressConfig() )->getEnabledExpressType($this->site_id);
  448. $this->assign('express_type', $express_type);
  449. $store_is_exit = addon_is_exit('store', $this->site_id);
  450. if ($store_is_exit && $goods_info[ 'sale_store' ] != 'all') {
  451. $store_list = ( new StoreModel() )->getStoreList([ [ 'site_id', '=', $this->site_id ], [ 'store_id', 'in', $goods_info[ 'sale_store' ] ] ], 'store_id,store_name,status,address,full_address,is_frozen');
  452. $this->assign('store_list', $store_list[ 'data' ]);
  453. }
  454. $this->assign('store_is_exit', $store_is_exit);
  455. return $this->fetch("goods/edit_goods");
  456. }
  457. }
  458. /**
  459. * 删除商品
  460. */
  461. public function deleteGoods()
  462. {
  463. if (request()->isAjax()) {
  464. $goods_ids = input("goods_ids", 0);
  465. $goods_model = new GoodsModel();
  466. $res = $goods_model->modifyIsDelete($goods_ids, 1, $this->site_id);
  467. return $res;
  468. }
  469. }
  470. /**
  471. * 商品回收站
  472. */
  473. public function recycle()
  474. {
  475. if (request()->isAjax()) {
  476. $page_index = input('page', 1);
  477. $page_size = input('page_size', PAGE_LIST_ROWS);
  478. $search_keys = input('search_text', "");
  479. $goods_class = input('goods_class', '');
  480. $condition = [ [ 'is_delete', '=', 1 ], [ 'site_id', "=", $this->site_id ] ];
  481. if (!empty($search_keys)) {
  482. $condition[] = [ 'goods_name', 'like', '%' . $search_keys . '%' ];
  483. }
  484. $category_id = input('category_id', "");
  485. if (!empty($category_id)) {
  486. $condition[] = [ 'category_id', 'like', '%,' . $category_id . ',%' ];
  487. }
  488. if ($goods_class !== "") {
  489. $condition[] = [ 'goods_class', '=', $goods_class ];
  490. }
  491. $goods_model = new GoodsModel();
  492. $res = $goods_model->getGoodsPageList($condition, $page_index, $page_size);
  493. return $res;
  494. } else {
  495. //获取一级商品分类
  496. $goods_category_model = new GoodsCategoryModel();
  497. $condition = [
  498. [ 'pid', '=', 0 ],
  499. [ 'site_id', '=', $this->site_id ]
  500. ];
  501. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate')[ 'data' ];
  502. $this->assign("goods_category_list", $goods_category_list);
  503. $this->assign('virtualcard_exit', addon_is_exit('virtualcard', $this->site_id));
  504. return $this->fetch("goods/recycle");
  505. }
  506. }
  507. /**
  508. * 商品回收站商品删除
  509. */
  510. public function deleteRecycleGoods()
  511. {
  512. if (request()->isAjax()) {
  513. $goods_ids = input("goods_ids", 0);
  514. $goods_model = new GoodsModel();
  515. $res = $goods_model->deleteRecycleGoods($goods_ids, $this->site_id);
  516. return $res;
  517. }
  518. }
  519. /**
  520. * 商品回收站商品恢复
  521. */
  522. public function recoveryRecycle()
  523. {
  524. if (request()->isAjax()) {
  525. $goods_ids = input("goods_ids", 0);
  526. $goods_model = new GoodsModel();
  527. $res = $goods_model->modifyIsDelete($goods_ids, 0, $this->site_id);
  528. return $res;
  529. }
  530. }
  531. /**
  532. * 商品下架
  533. */
  534. public function offGoods()
  535. {
  536. if (request()->isAjax()) {
  537. $goods_ids = input("goods_ids", 0);
  538. $goods_state = input("goods_state", 0);
  539. $goods_model = new GoodsModel();
  540. $res = $goods_model->modifyGoodsState($goods_ids, $goods_state, $this->site_id);
  541. return $res;
  542. }
  543. }
  544. /**
  545. * 商品上架
  546. */
  547. public function onGoods()
  548. {
  549. if (request()->isAjax()) {
  550. $goods_ids = input("goods_ids", 0);
  551. $goods_state = input("goods_state", 0);
  552. $goods_model = new GoodsModel();
  553. $res = $goods_model->modifyGoodsState($goods_ids, $goods_state, $this->site_id);
  554. return $res;
  555. }
  556. }
  557. /**
  558. * 编辑商品库存
  559. * @return array|\multitype
  560. */
  561. public function editGoodsStock()
  562. {
  563. if (request()->isAjax()) {
  564. $sku_list = input("sku_list", '');
  565. $model = new GoodsModel;
  566. $res = $model->editGoodsStock($sku_list, $this->site_id);
  567. return $res;
  568. }
  569. }
  570. /**
  571. * 获取商品分类列表
  572. * @return \multitype
  573. */
  574. public function getCategoryList()
  575. {
  576. if (request()->isAjax()) {
  577. $category_id = input("category_id", 0);
  578. $goods_category_model = new GoodsCategoryModel();
  579. $condition = [
  580. [ 'pid', '=', $category_id ],
  581. [ 'site_id', '=', $this->site_id ]
  582. ];
  583. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
  584. return $goods_category_list;
  585. }
  586. }
  587. /**
  588. * 获取商品参数列表
  589. * @return \multitype
  590. */
  591. public function getAttributeList()
  592. {
  593. if (request()->isAjax()) {
  594. $goods_attr_model = new GoodsAttributeModel();
  595. $attr_class_id = input('attr_class_id', 0);// 商品类型id
  596. $attribute_list = $goods_attr_model->getAttributeList([ [ 'attr_class_id', '=', $attr_class_id ], [ 'is_spec', '=', 0 ], [ 'site_id', '=', $this->site_id ] ], 'attr_id,attr_name,attr_class_id,attr_class_name,attr_type,attr_value_format', 'sort asc');
  597. if (!empty($attribute_list[ 'data' ])) {
  598. foreach ($attribute_list[ 'data' ] as $k => $v) {
  599. if (!empty($v[ 'attr_value_format' ])) {
  600. $attribute_list[ 'data' ][ $k ][ 'attr_value_format' ] = json_decode($v[ 'attr_value_format' ], true);
  601. }
  602. }
  603. }
  604. return $attribute_list;
  605. }
  606. }
  607. /**
  608. * 获取SKU商品列表
  609. * @return array
  610. */
  611. public function getGoodsSkuList()
  612. {
  613. if (request()->isAjax()) {
  614. $goods_id = input("goods_id", 0);
  615. $goods_model = new GoodsModel();
  616. $res = $goods_model->getGoodsSkuList([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], 'sku_id,sku_name,price,market_price,cost_price,stock,weight,volume,sku_no,sale_num,sku_image,spec_name,goods_id,stock_alarm,is_consume_discount,member_price,discount_method,discount_config,verify_num');
  617. if (!empty($res[ 'data' ])) {
  618. $res[ 'data' ] = $goods_model->getSkuMemberPrice($res[ 'data' ], $this->site_id);
  619. }
  620. return $res;
  621. }
  622. }
  623. /**
  624. * 商品选择组件
  625. * @return \multitype
  626. */
  627. public function goodsSelect()
  628. {
  629. if (request()->isAjax()) {
  630. $page = input('page', 1);
  631. $page_size = input('page_size', PAGE_LIST_ROWS);
  632. $search_text = input('search_text', '');
  633. $goods_id = input('goods_id', 0);
  634. $goods_ids = input('goods_ids', '');
  635. $is_virtual = input('is_virtual', '');// 是否虚拟类商品(0实物1.虚拟)
  636. $min_price = input('min_price', 0);
  637. $max_price = input('max_price', 0);
  638. $goods_class = input('goods_class', "");// 商品类型,实物、虚拟
  639. $category_id = input('category_id', "");// 商品分类id
  640. $promotion = input('promotion', '');//营销活动标识:pintuan、groupbuy、fenxiao、bargain
  641. $promotion_type = input('promotion_type', "");
  642. $label_id = input('label_id', "");
  643. $select_type = input('select_type', 'all');
  644. $usable_goods_class = input('usable_goods_class', '');
  645. $is_weigh = input('is_weigh', 0); // 是否支持称重
  646. if (!empty($promotion) && addon_is_exit($promotion)) {
  647. $promotion_name = input('promotion_name', '');// 营销活动
  648. $goods_list = event('GoodsListPromotion', [
  649. 'page' => $page,
  650. 'page_size' => $page_size,
  651. 'site_id' => $this->site_id,
  652. 'promotion' => $promotion,
  653. 'promotion_name' => $promotion_name,
  654. //筛选参数
  655. 'category_id' => $category_id,
  656. 'select_type' => $select_type,
  657. 'goods_ids' => $goods_ids,
  658. 'label_id' => $label_id,
  659. 'goods_class' => $goods_class,
  660. 'goods_name' => $search_text,
  661. ], true);
  662. } else {
  663. $goods_model = new GoodsModel();
  664. $condition = [
  665. [ 'is_delete', '=', 0 ],
  666. [ 'goods_state', '=', 1 ],
  667. [ 'goods_stock', '>', 0 ],
  668. [ 'site_id', '=', $this->site_id ]
  669. ];
  670. if ($is_weigh == 0) {
  671. $condition[] = [ 'goods_class', '<>', 6 ]; // 排除称重商品
  672. }
  673. if (!empty($search_text)) {
  674. $goods_sku_list = $goods_model->getGoodsSkuList([ [ 'sku_no', 'like', '%' . $search_text . '%' ] ], 'goods_id')[ 'data' ];
  675. $goods_id_arr = array_unique(array_column($goods_sku_list, 'goods_id'));
  676. if (!empty($goods_id_arr)) {
  677. $goods_ids = join(',', $goods_id_arr);
  678. $condition[] = [ '', 'exp', \think\facade\Db::raw("goods_name like '%{$search_text}%' or goods_id in ({$goods_ids})") ];
  679. } else {
  680. $condition[] = [ 'goods_name', 'like', "%{$search_text}%" ];
  681. }
  682. }
  683. if ($is_virtual !== "") {
  684. $condition[] = [ 'is_virtual', '=', $is_virtual ];
  685. }
  686. if (!empty($goods_id)) {
  687. $condition[] = [ 'goods_id', '=', $goods_id ];
  688. }
  689. if ($select_type == 'selected') {
  690. $condition[] = [ 'goods_id', 'in', $goods_ids ];
  691. }
  692. if (!empty($category_id)) {
  693. $condition[] = [ 'category_id', 'like', '%,' . $category_id . ',%' ];
  694. }
  695. if (!empty($promotion_type)) {
  696. $condition[] = [ 'promotion_addon', 'like', "%{$promotion_type}%" ];
  697. }
  698. if (!empty($label_id)) {
  699. $condition[] = [ 'label_id', '=', $label_id ];
  700. }
  701. if ($goods_class !== "") {
  702. $condition[] = [ 'goods_class', '=', $goods_class ];
  703. }
  704. if ($usable_goods_class != '') {
  705. $condition[] = [ 'goods_class', 'in', $usable_goods_class ];
  706. }
  707. if ($min_price != "" && $max_price != "") {
  708. $condition[] = [ 'price', 'between', [ $min_price, $max_price ] ];
  709. } elseif ($min_price != "") {
  710. $condition[] = [ 'price', '<=', $min_price ];
  711. } elseif ($max_price != "") {
  712. $condition[] = [ 'price', '>=', $max_price ];
  713. }
  714. $config_model = new ConfigModel();
  715. $sort_config = $config_model->getGoodsSort($this->site_id);
  716. $sort_config = $sort_config[ 'data' ][ 'value' ];
  717. $order = 'sort ' . $sort_config[ 'type' ] . ',create_time desc';
  718. $field = 'goods_id,goods_name,goods_class_name,goods_image,price,goods_stock,create_time,is_virtual';
  719. $goods_list = $goods_model->getGoodsPageList($condition, $page, $page_size, $order, $field);
  720. if (!empty($goods_list[ 'data' ][ 'list' ])) {
  721. foreach ($goods_list[ 'data' ][ 'list' ] as $k => $v) {
  722. $goods_list[ 'data' ][ 'list' ][ $k ][ 'sku_list' ] = $goods_model->getGoodsSkuList([ [ 'goods_id', '=', $v[ 'goods_id' ] ], [ 'site_id', '=', $this->site_id ] ], 'sku_id,sku_name,price,stock,sku_image,goods_id,goods_class_name', 'price asc')[ 'data' ];
  723. }
  724. }
  725. }
  726. return $goods_list;
  727. } else {
  728. //已经选择的商品sku数据
  729. $select_id = input('select_id', '');
  730. $mode = input('mode', 'spu');
  731. $max_num = input('max_num', 0);
  732. $min_num = input('min_num', 0);
  733. $is_virtual = input('is_virtual', '');
  734. $disabled = input('disabled', 0);
  735. $promotion = input('promotion', '');//营销活动标识:pintuan、groupbuy、seckill、fenxiao
  736. $goods_type = input('goods_type', ''); //查找商品类型
  737. $is_disabled_goods_type = input('is_disabled_goods_type', 0); //是否禁用商品类型筛选 0开启 1关闭
  738. $usable_goods_class = input('usable_goods_class', ''); // 可选择的商品类型
  739. $is_weigh = input('is_weigh', 0); // 是否支持称重
  740. $this->assign('is_disabled_goods_type', $is_disabled_goods_type);
  741. $this->assign('goods_type', $goods_type);
  742. $this->assign('select_id', $select_id);
  743. $this->assign('mode', $mode);
  744. $this->assign('max_num', $max_num);
  745. $this->assign('min_num', $min_num);
  746. $this->assign('is_virtual', $is_virtual);
  747. $this->assign('disabled', $disabled);
  748. $this->assign('promotion', $promotion);
  749. $this->assign('all_goodsclass', event('GoodsClass'));
  750. $this->assign('usable_goods_class', explode(',', $usable_goods_class));
  751. $this->assign('is_weigh', $is_weigh);
  752. // 营销活动
  753. $goods_promotion_type = event('GoodsPromotionType');
  754. $this->assign('promotion_type', $goods_promotion_type);
  755. // 商品分组
  756. $goods_label_model = new GoodsLabelModel();
  757. $label_list = $goods_label_model->getLabelList([ [ 'site_id', '=', $this->site_id ] ], 'id,label_name', 'sort asc')[ 'data' ];
  758. $this->assign("label_list", $label_list);
  759. //分类过滤
  760. if (!empty($promotion) && addon_is_exit($promotion)) {
  761. $category_id_arr = event('GoodsListCategoryIds', [
  762. 'promotion' => $promotion,
  763. 'site_id' => $this->site_id,
  764. ], true)[ 'data' ] ?? [];
  765. } else {
  766. $goods_model = new GoodsModel();
  767. $category_id_arr = $goods_model->getGoodsCategoryIds([
  768. [ 'is_delete', '=', 0 ],
  769. [ 'goods_state', '=', 1 ],
  770. [ 'goods_stock', '>', 0 ],
  771. [ 'site_id', '=', $this->site_id ],
  772. ])[ 'data' ];
  773. }
  774. $goods_category_model = new GoodsCategoryModel();
  775. $field = 'category_id,category_name as title,pid';
  776. $list = $goods_category_model->getCategoryList([
  777. [ 'site_id', '=', $this->site_id ],
  778. [ 'category_id', 'in', $category_id_arr ]
  779. ], $field)[ 'data' ];
  780. $tree = list_to_tree($list, 'category_id', 'pid', 'children', 0);
  781. $this->assign("category_list", $tree);
  782. $this->assign('virtualcard_exit', addon_is_exit('virtualcard', $this->site_id));
  783. $this->assign('cardservice_exit', addon_is_exit('cardservice', $this->site_id));
  784. $goods_model = new GoodsModel();
  785. $goods_model->getGoodsTotalCount();
  786. return $this->fetch("goods/goods_select");
  787. }
  788. }
  789. /***********************************************************商品评价**************************************************/
  790. /**
  791. * 商品评价
  792. */
  793. public function evaluate()
  794. {
  795. $goods_evaluate = new GoodsEvaluateModel();
  796. if (request()->isAjax()) {
  797. $page_index = input('page', 1);
  798. $page_size = input('page_size', PAGE_LIST_ROWS);
  799. $explain_type = input('explain_type', ''); //1好评2中评3差评
  800. $is_show = input('is_show', ''); //1显示 0隐藏
  801. $search_text = input('search_text', ''); //搜索值
  802. $search_type = input('search_type', ''); //搜索类型
  803. $start_time = input('start_time', '');
  804. $end_time = input('end_time', '');
  805. $goods_id = input('goods_id', '');
  806. $is_audit = input('is_audit', '');
  807. if (!empty($is_audit)) {
  808. if ($is_audit == 1) {
  809. $condition[] =
  810. [ "is_audit", "=", 0 ];
  811. } else if ($is_audit == 2) {
  812. $condition[] =
  813. [ "is_audit", "=", 1 ];
  814. } else if ($is_audit == 3) {
  815. $condition[] =
  816. [ "is_audit", "=", 2 ];
  817. }
  818. }
  819. $condition[] =
  820. [ "site_id", "=", $this->site_id ];
  821. //评分类型
  822. if ($explain_type != "") {
  823. $condition[] = [ "explain_type", "=", $explain_type ];
  824. }
  825. if ($is_show != "") {
  826. $condition[] = [ "is_show", "=", $is_show ];
  827. }
  828. if ($search_text != "") {
  829. $condition[] = [ $search_type, "like", '%' . $search_text . '%' ];
  830. }
  831. if ($goods_id != "") {
  832. $condition[] = [ 'goods_id', "=", $goods_id ];
  833. }
  834. if (!empty($start_time) && empty($end_time)) {
  835. $condition[] = [ "create_time", ">=", date_to_time($start_time) ];
  836. } elseif (empty($start_time) && !empty($end_time)) {
  837. $condition[] = [ "create_time", "<=", date_to_time($end_time) ];
  838. } elseif (!empty($start_time) && !empty($end_time)) {
  839. $condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  840. }
  841. return $goods_evaluate->getEvaluatePageList($condition, $page_index, $page_size, "is_audit asc, create_time desc");
  842. } else {
  843. $goods_id = input('goods_id', '');
  844. $this->assign('goods_id', $goods_id);
  845. return $this->fetch("goods/evaluate");
  846. }
  847. }
  848. /**
  849. * 商品评价删除
  850. */
  851. public function deleteEvaluate()
  852. {
  853. if (request()->isAjax()) {
  854. $goods_evaluate = new GoodsEvaluateModel();
  855. $evaluate_ids = input("evaluate_ids", 0);
  856. return $goods_evaluate->deleteEvaluate($evaluate_ids);
  857. }
  858. }
  859. /**
  860. * 修改商品评价审核状态
  861. */
  862. public function modifyAuditEvaluate()
  863. {
  864. if (request()->isAjax()) {
  865. $goods_evaluate = new GoodsEvaluateModel();
  866. $evaluate_ids = input("evaluate_ids", '');
  867. $is_audit = input('is_audit', 0);
  868. $data = [
  869. 'is_audit' => $is_audit
  870. ];
  871. $condition = [
  872. [ 'evaluate_id', 'in', $evaluate_ids ],
  873. [ 'is_audit', '=', 0 ],
  874. [ 'site_id', '=', $this->site_id ],
  875. ];
  876. $res = $goods_evaluate->modifyAuditEvaluate($data, $condition);
  877. return $res;
  878. }
  879. }
  880. /**
  881. * 修改商品追评审核状态
  882. */
  883. public function modifyAgainAuditEvaluate()
  884. {
  885. if (request()->isAjax()) {
  886. $goods_evaluate = new GoodsEvaluateModel();
  887. $evaluate_ids = input("evaluate_ids", '');
  888. $again_is_audit = input('again_is_audit', 0);
  889. $data = [
  890. 'again_is_audit' => $again_is_audit
  891. ];
  892. $condition = [
  893. [ 'evaluate_id', 'in', $evaluate_ids ],
  894. [ 'again_is_audit', '=', 0 ],
  895. [ 'site_id', '=', $this->site_id ],
  896. ];
  897. $res = $goods_evaluate->modifyAgainAuditEvaluate($data, $condition);
  898. return $res;
  899. }
  900. }
  901. /**
  902. * 商品推广
  903. * return
  904. */
  905. public function goodsUrl()
  906. {
  907. $goods_id = input('goods_id', '');
  908. $goods_model = new GoodsModel();
  909. $goods_sku_info = $goods_model->getGoodsSkuInfo([ [ 'goods_id', '=', $goods_id ] ], 'sku_id,goods_name,site_id')[ 'data' ];
  910. if (!empty($goods_sku_info)) {
  911. // $res = $goods_model->qrcode($goods_sku_info[ 'sku_id' ], $goods_sku_info[ 'goods_name' ], $goods_sku_info[ 'site_id' ]);
  912. $res = $goods_model->urlQrcode('/pages/goods/detail', [ 'goods_id' => $goods_id ], 'goods', $this->site_id);
  913. return $res;
  914. }
  915. }
  916. /**
  917. * 商品评价回复
  918. */
  919. public function evaluateApply()
  920. {
  921. if (request()->isAjax()) {
  922. $goods_evaluate = new GoodsEvaluateModel();
  923. $evaluate_id = input("evaluate_id", 0);
  924. $explain = input("explain", 0);
  925. $is_first_explain = input("is_first_explain", 0);// 是否第一次回复
  926. $data = [
  927. 'evaluate_id' => $evaluate_id
  928. ];
  929. if ($is_first_explain == 0) {
  930. $data[ 'explain_first' ] = $explain;
  931. } elseif ($is_first_explain == 1) {
  932. $data[ 'again_explain' ] = $explain;
  933. }
  934. return $goods_evaluate->evaluateApply($data);
  935. }
  936. }
  937. /**
  938. * 删除商品评价回复
  939. */
  940. public function deleteContent()
  941. {
  942. if (request()->isAjax()) {
  943. $goods_evaluate = new GoodsEvaluateModel();
  944. $evaluate_id = input("evaluate_id", 0);
  945. $is_first_explain = input("is_first", 0);// 0 第一次回复,1 追评回复
  946. $data = [];
  947. if ($is_first_explain == 0) {
  948. $data[ 'explain_first' ] = '';
  949. } elseif ($is_first_explain == 1) {
  950. $data[ 'again_explain' ] = '';
  951. }
  952. $condition = [
  953. [ 'evaluate_id', '=', $evaluate_id ],
  954. [ 'site_id', '=', $this->site_id ],
  955. ];
  956. return $goods_evaluate->editEvaluate($data, $condition);
  957. }
  958. }
  959. /**
  960. * 商品批量设置
  961. */
  962. public function batchSet()
  963. {
  964. if (request()->isAjax()) {
  965. $type = input("type", '');
  966. $goods_ids = input("goods_ids", '');
  967. $field = input("field", '');
  968. $data = !empty($field) ? json_decode($field, true) : [];
  969. $goods_model = new GoodsModel();
  970. $result = error(-1, '操作失败');
  971. try {
  972. if (!empty($goods_ids)) {
  973. switch ( $type ) {
  974. case 'group':
  975. $result = $goods_model->modifyGoodsLabel($data[ 'group' ], $this->site_id, $goods_ids);
  976. break;
  977. case 'service':
  978. $result = $goods_model->modifyGoodsService($data[ 'server_ids' ], $this->site_id, $goods_ids);
  979. break;
  980. case 'sale':
  981. $result = $goods_model->modifyGoodsVirtualSale($data[ 'sale' ], $this->site_id, $goods_ids);
  982. break;
  983. case 'purchase_limit':
  984. $result = $goods_model->modifyGoodsPurchaseLimit($data[ 'max_buy' ], $this->site_id, $goods_ids);
  985. break;
  986. case 'shipping':
  987. $result = $goods_model->modifyGoodsShippingTemplate($data[ 'is_free_shipping' ], $data[ 'shipping_template' ], $this->site_id, $goods_ids);
  988. break;
  989. case 'category':
  990. $result = $goods_model->modifyGoodsCategoryId($data[ 'category_id' ], $this->site_id, $goods_ids);
  991. //$result = ',' . implode(',', $data[ 'category_id' ]) . ',';
  992. break;
  993. case 'shop_intor':
  994. $result = $goods_model->modifyGoodsShopIntor($data[ 'recom_way' ], $this->site_id, $goods_ids);
  995. break;
  996. case 'member_price':
  997. $result = $goods_model->modifyGoodsConsumeDiscount($data[ 'is_consume_discount' ], $this->site_id, $goods_ids);
  998. break;
  999. case 'stock':
  1000. $sku_list = $goods_model->getGoodsSkuList([ [ 'goods_id', 'in', $goods_ids ], [ 'goods_class', 'in', '1,2,4,5,6' ] ], 'sku_id,goods_id,stock,goods_class')[ 'data' ] ?? [];
  1001. // 实物,虚拟,卡项,服务,称重
  1002. $result = $goods_model->editGoodsSkuStock($sku_list, $data[ 'stock' ], $data[ 'stock_type' ]);
  1003. break;
  1004. case 'price':
  1005. $batch_model = new Batch();
  1006. $params = array (
  1007. 'site_id' => $this->site_id,
  1008. 'type' => $type,
  1009. 'goods_ids' => $goods_ids,
  1010. );
  1011. $result = $batch_model->setPrice(array_merge($params, $data));
  1012. break;
  1013. case 'goods_form':
  1014. $result = $goods_model->modifyGoodsForm($data[ 'form_id' ], $this->site_id, $goods_ids);
  1015. break;
  1016. case 'goods_brand':
  1017. $result = $goods_model->modifyGoodsBrand($data[ 'brand_id' ], $this->site_id, $goods_ids);
  1018. break;
  1019. }
  1020. }
  1021. } catch (\Exception $e) {
  1022. $result = error(-1, $e->getMessage());
  1023. }
  1024. return $result;
  1025. }
  1026. }
  1027. /**
  1028. * 热门搜索关键词
  1029. * @return mixed
  1030. */
  1031. public function hotSearchWords()
  1032. {
  1033. $config_model = new ConfigModel();
  1034. if (request()->isAjax()) {
  1035. $words = input("words", []);
  1036. $data = [
  1037. 'words' => implode(',', $words)
  1038. ];
  1039. $res = $config_model->setHotSearchWords($data, $this->site_id, $this->app_module);
  1040. return $res;
  1041. } else {
  1042. $this->forthMenu();
  1043. $hot_search_words = $config_model->getHotSearchWords($this->site_id, $this->app_module);
  1044. $hot_search_words = $hot_search_words[ 'data' ][ 'value' ];
  1045. $words_array = [];
  1046. if (!empty($hot_search_words[ 'words' ])) {
  1047. $words_array = explode(',', $hot_search_words[ 'words' ]);
  1048. }
  1049. $hot_search_words[ 'words_array' ] = $words_array;
  1050. $this->assign("hot_search_words", $hot_search_words);
  1051. return $this->fetch('goods/hot_search_words');
  1052. }
  1053. }
  1054. /**
  1055. * 猜你喜欢
  1056. * @return mixed
  1057. */
  1058. public function guessYouLike()
  1059. {
  1060. $config_model = new ConfigModel();
  1061. if (request()->isAjax()) {
  1062. $value = input('value', '');
  1063. if (!empty($value)) {
  1064. $value = json_decode($value, true);
  1065. $res = $config_model->setGuessYouLike($value, $this->site_id, $this->app_module);
  1066. return $res;
  1067. }
  1068. } else {
  1069. $config = $config_model->getGuessYouLike($this->site_id, $this->app_module)[ 'data' ][ 'value' ];
  1070. $this->assign("config", $config);
  1071. $this->assign('store_is_exit', addon_is_exit('store', $this->site_id));
  1072. return $this->fetch('goods/guess_you_like');
  1073. }
  1074. }
  1075. /**
  1076. * 商品列表配置
  1077. * @return mixed
  1078. */
  1079. public function goodsListConfig()
  1080. {
  1081. $config_model = new ConfigModel();
  1082. if (request()->isAjax()) {
  1083. $value = input('value', '');
  1084. if (!empty($value)) {
  1085. $value = json_decode($value, true);
  1086. $res = $config_model->setGoodsListConfig($value, $this->site_id, $this->app_module);
  1087. return $res;
  1088. }
  1089. } else {
  1090. $config = $config_model->getGoodsListConfig($this->site_id, $this->app_module)[ 'data' ][ 'value' ];
  1091. $this->assign("config", $config);
  1092. $this->assign('store_is_exit', addon_is_exit('store', $this->site_id));
  1093. return $this->fetch('goods/goods_list_config');
  1094. }
  1095. }
  1096. /**
  1097. * 默认搜索关键词
  1098. * @return mixed
  1099. */
  1100. public function defaultSearchWords()
  1101. {
  1102. $config_model = new ConfigModel();
  1103. if (request()->isAjax()) {
  1104. $default_data = [
  1105. 'words' => input("default_words", "")
  1106. ];
  1107. $config_model->setDefaultSearchWords($default_data, $this->site_id, $this->app_module);
  1108. $words = input("words", []);
  1109. $data = [
  1110. 'words' => implode(',', $words)
  1111. ];
  1112. $res = $config_model->setHotSearchWords($data, $this->site_id, $this->app_module);
  1113. return $res;
  1114. } else {
  1115. $this->forthMenu();
  1116. $default_search_words = $config_model->getDefaultSearchWords($this->site_id, $this->app_module);
  1117. $default_search_words = $default_search_words[ 'data' ][ 'value' ];
  1118. $this->assign("default_search_words", $default_search_words);
  1119. $hot_search_words = $config_model->getHotSearchWords($this->site_id, $this->app_module);
  1120. $hot_search_words = $hot_search_words[ 'data' ][ 'value' ];
  1121. $words_array = [];
  1122. if (!empty($hot_search_words[ 'words' ])) {
  1123. $words_array = explode(',', $hot_search_words[ 'words' ]);
  1124. }
  1125. $hot_search_words[ 'words_array' ] = $words_array;
  1126. $this->assign("hot_search_words", $hot_search_words);
  1127. return $this->fetch('goods/default_search_words');
  1128. }
  1129. }
  1130. /**
  1131. * 复制商品
  1132. * @return array
  1133. */
  1134. public function copyGoods()
  1135. {
  1136. if (request()->isAjax()) {
  1137. $goods_id = input('goods_id', 0);
  1138. $goods_model = new GoodsModel();
  1139. $res = $goods_model->copyGoods($goods_id, $this->site_id);
  1140. return $res;
  1141. }
  1142. }
  1143. /**
  1144. * 会员商品收藏
  1145. */
  1146. public function memberGoodsCollect()
  1147. {
  1148. $goods_collect_model = new GoodsCollect();
  1149. $member_id = input('member_id', 0);
  1150. if (request()->isAjax()) {
  1151. $page = input('page', 1);
  1152. $page_size = input('page_size', PAGE_LIST_ROWS);
  1153. $condition = [];
  1154. $condition[] = [ 'gc.site_id', '=', $this->site_id ];
  1155. $condition[] = [ 'gc.member_id', '=', $member_id ];
  1156. $order = 'gc.create_time desc';
  1157. $field = 'gc.collect_id,gc.create_time,gc.member_id, gc.goods_id, gc.sku_id,gc.sku_name, gc.sku_price, gc.sku_image,g.goods_name,g.is_free_shipping,sku.promotion_type,sku.member_price,sku.discount_price,g.sale_num,g.price,g.market_price,g.is_virtual,sku.collect_num,g.goods_state';
  1158. return $goods_collect_model->getCollectPageList($condition, $page, $page_size, $order, $field);
  1159. } else {
  1160. $this->forthMenu([ 'member_id' => $member_id ]);
  1161. $this->assign('member_id', $member_id);
  1162. return $this->fetch('goods/member_goods_collect');
  1163. }
  1164. }
  1165. /**
  1166. * 会员浏览记录
  1167. */
  1168. public function memberGoodsBrowse()
  1169. {
  1170. $member_id = input('member_id', 0);
  1171. $goods_browse_model = new GoodsBrowse();
  1172. if (request()->isAjax()) {
  1173. $page = input('page', 1);
  1174. $page_size = input('page_size', PAGE_LIST_ROWS);
  1175. $search = input('search', '');
  1176. $condition = [];
  1177. $condition[] = [ 'gb.site_id', '=', $this->site_id ];
  1178. $condition[] = [ 'gb.member_id', '=', $member_id ];
  1179. if (!empty($search)) {
  1180. $condition[] = [ 'gs.sku_name', 'like', '%' . $search . '%' ];
  1181. }
  1182. $order = 'browse_time desc';
  1183. $field = 'gb.*,gs.sku_name,gs.sku_image,gs.price,gs.goods_state,gs.stock,gs.click_num';
  1184. $alias = 'gb';
  1185. $join = [
  1186. [ 'goods_sku gs', 'gs.sku_id = gb.sku_id', 'right' ]
  1187. ];
  1188. return $goods_browse_model->getBrowsePageList($condition, $page, $page_size, $order, $field, $alias, $join);
  1189. } else {
  1190. $this->forthMenu([ 'member_id' => $member_id ]);
  1191. $this->assign('member_id', $member_id);
  1192. return $this->fetch('goods/member_goods_browse');
  1193. }
  1194. }
  1195. /**
  1196. * 商品浏览记录
  1197. */
  1198. public function goodsBrowse()
  1199. {
  1200. $goods_id = input('goods_id', 0);
  1201. $goods_browse_model = new GoodsBrowse();
  1202. if (request()->isAjax()) {
  1203. $page = input('page', 1);
  1204. $page_size = input('page_size', PAGE_LIST_ROWS);
  1205. $search = input('search', '');
  1206. $condition = [];
  1207. $condition[] = [ 'gb.site_id', '=', $this->site_id ];
  1208. if ($goods_id > 0) {
  1209. $condition[] = [ 'gb.goods_id', '=', $goods_id ];
  1210. }
  1211. if (!empty($search))
  1212. $condition[] = [ 'gs.sku_name', 'like', '%' . $search . '%' ];
  1213. $order = 'browse_time desc';
  1214. $field = 'gb.*,gs.sku_name,gs.sku_image,gs.price,gs.goods_state,gs.stock,gs.click_num,m.nickname,m.headimg';
  1215. $alias = 'gb';
  1216. $join = [
  1217. [ 'goods_sku gs', 'gs.sku_id = gb.sku_id', 'left' ],
  1218. [ 'member m', 'm.member_id = gb.member_id', 'left' ]
  1219. ];
  1220. $res = $goods_browse_model->getBrowsePageList($condition, $page, $page_size, $order, $field, $alias, $join);
  1221. foreach ($res[ 'data' ][ 'list' ] as $k => $v) {
  1222. $res[ 'data' ][ 'list' ][ $k ][ 'stock' ] = numberFormat($res[ 'data' ][ 'list' ][ $k ][ 'stock' ]);
  1223. }
  1224. return $res;
  1225. } else {
  1226. $this->assign('goods_id', $goods_id);
  1227. return $this->fetch('goods/goods_browse');
  1228. }
  1229. }
  1230. /**
  1231. * 商品排序
  1232. */
  1233. public function goodssort()
  1234. {
  1235. $config_model = new ConfigModel();
  1236. if (request()->isAjax()) {
  1237. $type = input("type", 'asc');
  1238. $default_value = input("default_value", '0');
  1239. $data = [
  1240. 'type' => trim($type),
  1241. 'default_value' => trim($default_value),
  1242. ];
  1243. $res = $config_model->setGoodsSort($data, $this->site_id, $this->app_module);
  1244. return $res;
  1245. } else {
  1246. $this->forthMenu();
  1247. $goods_sort_confog = $config_model->getGoodsSort($this->site_id, $this->app_module);
  1248. $goods_sort_confog = $goods_sort_confog[ 'data' ][ 'value' ];
  1249. $this->assign("goods_sort_confog", $goods_sort_confog);
  1250. return $this->fetch('goods/goods_sort');
  1251. }
  1252. }
  1253. /**
  1254. * 商品导入
  1255. */
  1256. public function import()
  1257. {
  1258. $import_model = new GoodsImport();
  1259. $type = input('type');
  1260. if (request()->isAjax()) {
  1261. $file = request()->file('xlsx');
  1262. if (empty($file)) {
  1263. return $import_model->error();
  1264. }
  1265. $tmp_name = $file->getPathname();//获取上传缓存文件
  1266. $data = ( new GoodsImport() )->readGoodsExcel($tmp_name);
  1267. if ($data[ 'code' ] < 0) {
  1268. return $data;
  1269. }
  1270. $result = ( new GoodsImport() )->importGoods($data[ 'data' ], $this->site_id, $type);
  1271. return $result;
  1272. } else {
  1273. return $this->fetch("goods/import");
  1274. }
  1275. }
  1276. public function importRecordList()
  1277. {
  1278. $page_index = input('page', 1);
  1279. $page_size = input('page_size', PAGE_LIST_ROWS);
  1280. $goodsimport_model = new GoodsImport();
  1281. if (request()->isAjax()) {
  1282. $start_time = input('start_time', '');
  1283. $end_time = input('end_time', '');
  1284. $condition = [ [ 'site_id', '=', $this->site_id ] ];
  1285. if (!empty($start_time) && empty($end_time)) {
  1286. $condition[] = [ "import_time", ">=", date_to_time($start_time) ];
  1287. } elseif (empty($start_time) && !empty($end_time)) {
  1288. $condition[] = [ "import_time", "<=", date_to_time($end_time) ];
  1289. } elseif (!empty($start_time) && !empty($end_time)) {
  1290. $condition[] = [ 'import_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  1291. }
  1292. $res = $goodsimport_model->getImportPageList($condition, $page_index, $page_size);
  1293. if (!empty($res[ 'data' ][ 'list' ])) {
  1294. foreach ($res[ 'data' ][ 'list' ] as $k => &$v) {
  1295. $v[ 'import_time' ] = time_to_date($v[ 'import_time' ]);
  1296. }
  1297. }
  1298. return $res;
  1299. } else {
  1300. return $this->fetch("goods/import_record_list");
  1301. }
  1302. }
  1303. public function download()
  1304. {
  1305. $id = input('id', '0');
  1306. ( new GoodsImport() )->downloadFailData($id, $this->site_id);
  1307. }
  1308. /**
  1309. * 商品海报
  1310. */
  1311. public function poster()
  1312. {
  1313. $goods_poster_model = new GoodsPoster();
  1314. if (request()->isAjax()) {
  1315. $page = input('page', 1);
  1316. $page_size = input('page_size', PAGE_LIST_ROWS);
  1317. $keywords = input('keywords', '');
  1318. if (!empty($keywords)) {
  1319. $condition[] = [ 'poster_name', 'like', '%' . $keywords . '%' ];
  1320. }
  1321. $condition[] = [ 'site_id', '=', $this->site_id ];
  1322. $result = $goods_poster_model->getPosterPageList($condition, $page, $page_size);
  1323. return $result;
  1324. } else {
  1325. return $this->fetch("goods/goods_poster_list");
  1326. }
  1327. }
  1328. /**
  1329. * 商品海报添加
  1330. */
  1331. public function editPoster()
  1332. {
  1333. $goods_poster_model = new GoodsPoster();
  1334. if (request()->isAjax()) {
  1335. $poster_name = input('poster_name', '');
  1336. $json_data = input('json_data', '');
  1337. $poster_id = input('poster_id', '');
  1338. if (empty($poster_id)) {
  1339. $data[ 'create_time' ] = time();
  1340. } else {
  1341. $data[ 'modify_time' ] = time();
  1342. }
  1343. $data[ 'poster_id' ] = $poster_id;
  1344. $data[ 'poster_name' ] = $poster_name;
  1345. $data[ 'json_data' ] = $json_data;
  1346. $data[ 'poster_type' ] = 1;
  1347. $data[ 'site_id' ] = $this->site_id;
  1348. $result = $goods_poster_model->addPoster($data);
  1349. return $result;
  1350. } else {
  1351. $poster_id = input('poster_id', '');
  1352. if (!empty($poster_id)) {
  1353. $goods_poster_data = $goods_poster_model->getPosterInfo($poster_id, $this->site_id);
  1354. $this->assign('poster_data', $goods_poster_data[ 'data' ]);
  1355. }
  1356. return $this->fetch("goods/goods_edit_poster");
  1357. }
  1358. }
  1359. /**
  1360. * 修改海报启用状态
  1361. */
  1362. public function editStatus()
  1363. {
  1364. $goods_poster_model = new GoodsPoster();
  1365. $poster_id = input('poster_id', 0);
  1366. $status = input('status', '');
  1367. $data = [
  1368. 'poster_id' => $poster_id,
  1369. 'status' => $status,
  1370. 'site_id' => $this->site_id,
  1371. 'modify_time' => time()
  1372. ];
  1373. return $goods_poster_model->addPoster($data);
  1374. }
  1375. /**
  1376. * 删除海报
  1377. */
  1378. public function deletePoster()
  1379. {
  1380. $goods_poster_model = new GoodsPoster();
  1381. $poster_id = input('poster_id', 0);
  1382. return $goods_poster_model->deletePoster($poster_id, $this->site_id);
  1383. }
  1384. public function verify()
  1385. {
  1386. $goods_id = input("goods_id", "0");
  1387. $virtual_goods_model = new \app\model\goods\VirtualGoods();
  1388. if (request()->isAjax()) {
  1389. $start_time = input("start_time", '');
  1390. $end_time = input("end_time", '');
  1391. $nickname = input("nickname", '');
  1392. $is_verify = input("is_verify", "all");
  1393. $verify_code = input("verify_code", "");
  1394. $field = 'gv.*, m.nickname,m.headimg';
  1395. $page_index = input('page', 1);
  1396. $page_size = input('page_size', PAGE_LIST_ROWS);
  1397. $alias = 'gv';
  1398. $condition = [
  1399. [ "gv.site_id", "=", $this->site_id ],
  1400. [ "gv.goods_id", "=", $goods_id ],
  1401. ];
  1402. if ($nickname) $condition[] = [ 'm.nickname', 'like', '%' . $nickname . '%' ];
  1403. if ($verify_code) $condition[] = [ 'gv.code', '=', $verify_code ];
  1404. $order = "gv.id desc";
  1405. $join = [
  1406. [
  1407. 'member m',
  1408. 'm.member_id = gv.member_id',
  1409. 'left'
  1410. ]
  1411. ];
  1412. if ($is_verify != "all") {
  1413. $condition[] = [ "gv.is_veirfy", "=", $is_verify ];
  1414. }
  1415. $list = $virtual_goods_model->getVirtualGoodsPageList($condition, $page_index, $page_size, $order, $field, $alias, $join);
  1416. return $list;
  1417. }
  1418. $this->assign('goods_id', $goods_id);
  1419. $goods_model = new GoodsModel();
  1420. $goods_info = $goods_model->getGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], 'goods_id, goods_name,goods_image,price,goods_state,goods_stock,sale_num');
  1421. $this->assign('goods_info', $goods_info[ 'data' ]);
  1422. $verify_count = $virtual_goods_model->getVirtualGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], 'count(id) as total_count, sum(verify_use_num) as verify_use_num')[ 'data' ] ?? [];
  1423. $this->assign('total_count', $verify_count[ 'total_count' ] ?? 0);
  1424. $this->assign('verify_use_num', $verify_count[ 'verify_use_num' ] ?? 0);
  1425. return $this->fetch("goods/verify");
  1426. }
  1427. /**
  1428. * 商品详情配置
  1429. * @return mixed
  1430. */
  1431. public function goodsDetailConfig()
  1432. {
  1433. $config_model = new ConfigModel();
  1434. if (request()->isAjax()) {
  1435. $data = [
  1436. 'nav_bar_switch' => input('nav_bar_switch', 0),
  1437. 'introduction_color' => input('introduction_color', ''),
  1438. ];
  1439. $res = $config_model->setGoodsDetailConfig($data, $this->site_id, $this->app_module);
  1440. return $res;
  1441. } else {
  1442. $config = $config_model->getGoodsDetailConfig($this->site_id, $this->app_module)[ 'data' ][ 'value' ];
  1443. $this->assign("config", $config);
  1444. return $this->fetch('goods/goods_detail_config');
  1445. }
  1446. }
  1447. /**
  1448. * 获取运费模板
  1449. * @return array
  1450. */
  1451. public function getExpressTemplateList()
  1452. {
  1453. if (request()->isAjax()) {
  1454. $express_template_model = new ExpressTemplateModel();
  1455. $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc') ?? [];
  1456. // foreach ($express_template_list[ 'data' ] as $k => $v) {
  1457. // $template_item_condition = array (
  1458. // [ 'template_id', '=', $v[ 'template_id' ] ],
  1459. // );
  1460. // $template_item_list = $express_template_model->getExpressTemplateItemList($template_item_condition)[ 'data' ] ?? [];
  1461. // $express_template_list[ 'data' ][ $k ][ 'template_item_list' ] = $template_item_list;
  1462. // }
  1463. return $express_template_list;
  1464. }
  1465. }
  1466. /**
  1467. * 验证商品编码是否重复
  1468. * @return array
  1469. */
  1470. public function verifySkuNo()
  1471. {
  1472. if (request()->isAjax()) {
  1473. $sku_no = input('sku_no', '');
  1474. $goods_id = input('goods_id', 0);
  1475. $goods_model = new GoodsModel();
  1476. $res = $goods_model->verifySkuNo([
  1477. 'site_id' => $this->site_id,
  1478. 'sku_no' => $sku_no,
  1479. 'goods_id' => $goods_id
  1480. ]);
  1481. return $res;
  1482. }
  1483. }
  1484. /**
  1485. * 商品导出
  1486. */
  1487. public function exportGoods()
  1488. {
  1489. if (request()->isAjax()) {
  1490. $search_text = input('search_text', "");
  1491. $goods_state = input('goods_state', "");
  1492. $start_sale = input('start_sale', 0);
  1493. $end_sale = input('end_sale', 0);
  1494. $start_price = input('start_price', 0);
  1495. $end_price = input('end_price', 0);
  1496. $sku_start_price = input('sku_start_price', 0);
  1497. $sku_end_price = input('sku_end_price', 0);
  1498. $goods_class = input('goods_class', "");
  1499. $label_id = input('label_id', "");
  1500. $brand_id = input('brand_id', "");
  1501. $sku_no = input('sku_no', '');
  1502. $promotion_type = input('promotion_type', "");
  1503. $category_id = input('category_id', "");
  1504. $stockalarm = input('stockalarm', 0);
  1505. $goods_ids = input('goods_ids', '');
  1506. $goods_model = new GoodsModel();
  1507. $condition_desc = [];
  1508. $condition = [
  1509. [ 'g.is_delete', '=', 0 ],
  1510. [ 'g.site_id', '=', $this->site_id ],
  1511. ];
  1512. if (!empty($goods_ids)) {
  1513. $condition[] = [ 'g.goods_id', 'in', explode(',', $goods_ids) ];
  1514. $condition_desc[] = [ 'name' => 'goods_id', 'value' => $goods_ids ];
  1515. }
  1516. if (!empty($search_text)) {
  1517. $condition[] = [ 'g.goods_name', 'like', '%' . $search_text . '%' ];
  1518. $condition_desc[] = [ 'name' => '商品名称', 'value' => $search_text ];
  1519. }
  1520. if (!empty($sku_no)) {
  1521. $goods_sku_list = $goods_model->getGoodsSkuList([ [ 'sku_no', 'like', '%' . $sku_no . '%' ] ], 'goods_id')[ 'data' ];
  1522. $goods_id_arr = array_unique(array_column($goods_sku_list, 'goods_id'));
  1523. $condition[] = [ 'goods_id', 'in', $goods_id_arr ];
  1524. $condition_desc[] = [ 'name' => '商品编码', 'value' => $sku_no ];
  1525. }
  1526. if (!empty($category_id)) {
  1527. $condition[] = [ 'g.category_id', '=', $category_id ];
  1528. $goods_category_model = new GoodsCategoryModel();
  1529. $category_info = $goods_category_model->getCategoryInfo([
  1530. [ 'category_id', '=', $category_id ],
  1531. [ 'site_id', '=', $this->site_id ]
  1532. ], 'category_name')[ 'data' ];
  1533. if (!empty($category_info)) {
  1534. $condition_desc[] = [ 'name' => '商品分类', 'value' => $category_info[ 'category_name' ] ];
  1535. }
  1536. }
  1537. $brand_name = '全部';
  1538. if (!empty($brand_id)) {
  1539. $condition[] = [ 'g.brand_id', '=', $brand_id ];
  1540. $goods_brand_model = new GoodsBrandModel();
  1541. $goods_brand_info = $goods_brand_model->getBrandInfo([
  1542. [ 'site_id', '=', $this->site_id ],
  1543. ], 'brand_name')[ 'data' ];
  1544. if (!empty($goods_brand_info)) {
  1545. $brand_name = $goods_brand_info[ 'brand_name' ];
  1546. }
  1547. }
  1548. $condition_desc[] = [ 'name' => '商品品牌', 'value' => $brand_name ];
  1549. $goods_class_name = '全部';
  1550. if ($goods_class !== "") {
  1551. $condition[] = [ 'g.goods_class', '=', $goods_class ];
  1552. $goods_class_info = array_column(event('GoodsClass'), null, 'goods_class');
  1553. $goods_class_name = $goods_class_info[ $goods_class ][ 'goods_class_name' ];
  1554. }
  1555. $condition_desc[] = [ 'name' => '商品类型', 'value' => $goods_class_name ];
  1556. $label_name = '全部';
  1557. if (!empty($label_id)) {
  1558. $condition[] = [ 'g.label_id', '=', $label_id ];
  1559. $goods_label_model = new GoodsLabelModel();
  1560. $label_info = $goods_label_model->getLabelInfo([
  1561. [ 'site_id', '=', $this->site_id ],
  1562. [ 'label_id', '=', $label_id ]
  1563. ], 'label_name')[ 'data' ];
  1564. if (!empty($label_info)) {
  1565. $label_name = $label_info[ 'label_name' ];
  1566. }
  1567. }
  1568. $condition_desc[] = [ 'name' => '商品标签', 'value' => $label_name ];
  1569. if (!empty($promotion_type)) {
  1570. $condition[] = [ 'g.promotion_addon', 'like', "%{$promotion_type}%" ];
  1571. }
  1572. // 上架状态
  1573. if ($goods_state !== '') {
  1574. $condition[] = [ 'g.goods_state', '=', $goods_state ];
  1575. $condition_desc[] = [ 'name' => '商品状态', 'value' => $goods_state == 1 ? '销售中' : '仓库中' ];
  1576. }
  1577. if (!empty($start_sale)) $condition[] = [ 'sale_num', ' >= ', $start_sale ];
  1578. if (!empty($end_sale)) $condition[] = [ 'sale_num', ' <= ', $end_sale ];
  1579. if (!empty($start_price)) $condition[] = [ 'price', ' >= ', $start_price ];
  1580. if (!empty($end_price)) $condition[] = [ 'price', ' <= ', $end_price ];
  1581. if (!empty($sku_start_price)) $condition[] = [ 'sku.price', ' >= ', $sku_start_price ];
  1582. if (!empty($sku_end_price)) $condition[] = [ 'sku.price', ' <= ', $sku_end_price ];
  1583. // 查询库存预警的商品
  1584. if ($stockalarm) {
  1585. $stock_alarm = $goods_model->getGoodsStockAlarm($this->site_id);
  1586. if (!empty($stock_alarm[ 'data' ])) {
  1587. $condition[] = [ 'goods_id', 'in', $stock_alarm[ 'data' ] ];
  1588. } else {
  1589. return success(0, '', [ 'page_count' => 1, 'count' => 0, 'list' => [] ]);
  1590. }
  1591. }
  1592. $goods_export_model = new GoodsExport();
  1593. $result = $goods_export_model->export($condition, $condition_desc, $this->site_id);
  1594. return $result;
  1595. }
  1596. }
  1597. /**
  1598. * 导出记录
  1599. * @return array|mixed
  1600. */
  1601. public function export()
  1602. {
  1603. if (request()->isAjax()) {
  1604. $page_index = input('page', 1);
  1605. $page_size = input('page_size', PAGE_LIST_ROWS);
  1606. $export_model = new GoodsExport();
  1607. $condition = array (
  1608. [ 'site_id', '=', $this->site_id ]
  1609. );
  1610. $result = $export_model->getExportPageList($condition, $page_index, $page_size, 'create_time desc', ' * ');
  1611. return $result;
  1612. } else {
  1613. return $this->fetch('goods/export');
  1614. }
  1615. }
  1616. /**
  1617. * 删除导出记录
  1618. * @return array
  1619. */
  1620. public function deleteExport()
  1621. {
  1622. if (request()->isAjax()) {
  1623. $export_ids = input('export_ids', '');
  1624. $export_model = new GoodsExport();
  1625. $condition = array (
  1626. [ 'site_id', '=', $this->site_id ],
  1627. [ 'export_id', 'in', (string) $export_ids ]
  1628. );
  1629. $result = $export_model->deleteExport($condition);
  1630. return $result;
  1631. }
  1632. }
  1633. }