Goods.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\shop\controller;
  13. use app\model\express\ExpressTemplate as ExpressTemplateModel;
  14. use app\model\goods\Goods as GoodsModel;
  15. use app\model\goods\GoodsAttribute as GoodsAttributeModel;
  16. use app\model\goods\GoodsBrand as GoodsBrandModel;
  17. use app\model\goods\GoodsCategory as GoodsCategoryModel;
  18. use app\model\goods\GoodsShopCategory as GoodsShopCategoryModel;
  19. use app\model\goods\GoodsEvaluate as GoodsEvaluateModel;
  20. use app\model\goods\GoodsShopCategory;
  21. use addon\supply\model\Supplier as SupplierModel;
  22. /**
  23. * 实物商品
  24. * Class Goods
  25. * @package app\shop\controller
  26. */
  27. class Goods extends BaseShop
  28. {
  29. public function __construct()
  30. {
  31. //执行父类构造函数
  32. parent::__construct();
  33. }
  34. /**
  35. * 商品列表
  36. * @return mixed
  37. */
  38. public function lists()
  39. {
  40. $goods_model = new GoodsModel();
  41. if (request()->isAjax()) {
  42. $page_index = input('page', 1);
  43. $page_size = input('page_size', PAGE_LIST_ROWS);
  44. $search_text = input('search_text', "");
  45. $goods_state = input('goods_state', "");
  46. $verify_state = input('verify_state', "");
  47. $start_sale = input('start_sale', 0);
  48. $end_sale = input('end_sale', 0);
  49. $start_price = input('start_price', 0);
  50. $end_price = input('end_price', 0);
  51. $goods_shop_category_ids = input('goods_shop_category_ids', '');
  52. $goods_class = input('goods_class', "");
  53. $condition = [ [ 'is_delete', '=', 0 ], [ 'site_id', '=', $this->site_id ] ];
  54. if (!empty($search_text)) {
  55. $condition[] = [ 'goods_name', 'like', '%' . $search_text . '%' ];
  56. }
  57. if ($goods_class !== "") {
  58. $condition[] = [ 'goods_class', '=', $goods_class ];
  59. }
  60. // 上架状态
  61. if ($goods_state !== '') {
  62. $condition[] = [ 'goods_state', '=', $goods_state ];
  63. }
  64. // 审核状态
  65. if ($verify_state !== '') {
  66. $condition[] = [ 'verify_state', '=', $verify_state ];
  67. }
  68. if (!empty($start_sale)) $condition[] = [ 'sale_num', '>=', $start_sale ];
  69. if (!empty($end_sale)) $condition[] = [ 'sale_num', '<=', $end_sale ];
  70. if (!empty($start_price)) $condition[] = [ 'price', '>=', $start_price ];
  71. if (!empty($end_price)) $condition[] = [ 'price', '<=', $end_price ];
  72. if (!empty($goods_shop_category_ids)) $condition[] = [ 'goods_shop_category_ids', 'like', [ $goods_shop_category_ids, '%' . $goods_shop_category_ids . ',%', '%' . $goods_shop_category_ids, '%,' . $goods_shop_category_ids . ',%' ], 'or' ];
  73. $res = $goods_model->getGoodsPageList($condition, $page_index, $page_size);
  74. return $res;
  75. } else {
  76. $verify_state = $goods_model->getVerifyState();
  77. $arr = [];
  78. foreach ($verify_state as $k => $v) {
  79. // 过滤已审核状态
  80. if ($k != 1) {
  81. $total = $goods_model->getGoodsTotalCount([ [ 'verify_state', '=', $k ], [ 'site_id', "=", $this->site_id ] ]);
  82. $total = $total['data'];
  83. $arr[] = [
  84. 'state' => $k,
  85. 'value' => $v,
  86. 'count' => $total
  87. ];
  88. }
  89. }
  90. $verify_state = $arr;
  91. $this->assign("verify_state", $verify_state);
  92. //获取店内分类
  93. $goods_shop_category_model = new GoodsShopCategoryModel();
  94. $goods_shop_category_list = $goods_shop_category_model->getShopCategoryTree([ [ 'site_id', "=", $this->site_id ] ], 'category_id,category_name,pid,level');
  95. $goods_shop_category_list = $goods_shop_category_list['data'];
  96. $this->assign("goods_shop_category_list", $goods_shop_category_list);
  97. return $this->fetch("goods/lists");
  98. }
  99. }
  100. /**
  101. * 刷新审核状态商品数量
  102. */
  103. public function refreshVerifyStateCount()
  104. {
  105. if (request()->isAjax()) {
  106. $goods_model = new GoodsModel();
  107. $verify_state = $goods_model->getVerifyState();
  108. $arr = [];
  109. foreach ($verify_state as $k => $v) {
  110. // 过滤已审核状态
  111. if ($k != 1) {
  112. $total = $goods_model->getGoodsTotalCount([ [ 'verify_state', '=', $k ], [ 'site_id', "=", $this->site_id ] ]);
  113. $total = $total['data'];
  114. $arr[] = [
  115. 'state' => $k,
  116. 'value' => $v,
  117. 'count' => $total
  118. ];
  119. }
  120. }
  121. $verify_state = $arr;
  122. return $verify_state;
  123. }
  124. }
  125. /**
  126. * 添加商品
  127. * @return mixed
  128. */
  129. public function addGoods()
  130. {
  131. if (request()->isAjax()) {
  132. $goods_model = new GoodsModel();
  133. if ($this->shop_info["shop_status"] == 0) {
  134. return $goods_model->error([], "SHOP_IS_CLOSE");
  135. }
  136. $goods_name = input("goods_name", "");// 商品名称
  137. $goods_attr_class = input("goods_attr_class", "");// 商品类型id
  138. $goods_attr_name = input("goods_attr_name", "");// 商品类型名称
  139. $category_id = input("category_id", 0);// 分类id
  140. $category_id_1 = input("category_id_1", 0);// 一级分类id
  141. $category_id_2 = input("category_id_2", 0);// 二级分类id
  142. $category_id_3 = input("category_id_3", 0);// 三级分类id
  143. $category_name = input("category_name", "");// 所属分类名称
  144. $commission_rate = input("commission_rate", 0);// 分佣比率(按照分类)
  145. $brand_id = input("brand_id", 0);// 品牌id
  146. $brand_name = input("brand_name", "");// 所属品牌名称
  147. $goods_shop_category_ids = input("goods_shop_category_ids", "");// 店内分类id,逗号隔开
  148. $goods_image = input("goods_image", "");// 商品主图路径
  149. $goods_content = input("goods_content", "");// 商品详情
  150. $goods_state = input("goods_state", "");// 商品状态(1.正常0下架)
  151. $goods_stock = input("goods_stock", 0);// 商品库存(总和)
  152. $goods_stock_alarm = input("goods_stock_alarm", 0);// 库存预警
  153. $is_free_shipping = input("is_free_shipping", 1);// 是否免邮
  154. $shipping_template = input("shipping_template", 0);// 指定运费模板
  155. $goods_spec_format = input("goods_spec_format", "");// 商品规格格式
  156. $goods_attr_format = input("goods_attr_format", "");// 商品属性格式
  157. $introduction = input("introduction", "");// 促销语
  158. $keywords = input("keywords", "");// 关键词
  159. $unit = input("unit", "");// 单位
  160. $sort = input("sort", 0);// 排序
  161. $video_url = input("video_url", "");// 视频
  162. $goods_sku_data = input("goods_sku_data", "");// SKU商品数据
  163. $supplier_id = input("supplier_id", "");// 供应商id
  164. $pay_num1 = input("pay_num1",0);
  165. $price1 = input("price1",0);
  166. $pay_num2 = input("pay_num2",0);
  167. $price2 =input("price2",0);
  168. $pay_num3 = input("pay_num3",0);
  169. $price3 = input("price3",0);
  170. $province = input("province",0);
  171. $city = input("city",0);
  172. // print_r($goods_sku_data);die;
  173. //单规格需要
  174. $price = input("price", 0);// 商品价格(取第一个sku)
  175. $market_price = input("market_price", 0);// 市场价格(取第一个sku)
  176. $cost_price = input("cost_price", 0);// 成本价(取第一个sku)
  177. $sku_no = input("sku_no", "");// 商品sku编码
  178. $weight = input("weight", "");// 重量
  179. $volume = input("volume", "");// 体积
  180. $data = [
  181. 'goods_name' => $goods_name,
  182. 'goods_attr_class' => $goods_attr_class,
  183. 'goods_attr_name' => $goods_attr_name,
  184. 'site_id' => $this->site_id,
  185. 'website_id' => $this->website_id,
  186. 'category_id' => $category_id,
  187. 'category_id_1' => $category_id_1,
  188. 'category_id_2' => $category_id_2,
  189. 'category_id_3' => $category_id_3,
  190. 'category_name' => $category_name,
  191. 'brand_id' => $brand_id,
  192. 'brand_name' => $brand_name,
  193. 'goods_image' => $goods_image,
  194. 'goods_content' => $goods_content,
  195. 'goods_state' => $goods_state,
  196. 'price' => $price,
  197. 'market_price' => $market_price,
  198. 'cost_price' => $cost_price,
  199. 'sku_no' => $sku_no,
  200. 'weight' => $weight,
  201. 'volume' => $volume,
  202. 'goods_stock' => $goods_stock,
  203. 'goods_stock_alarm' => $goods_stock_alarm,
  204. 'is_free_shipping' => $is_free_shipping,
  205. 'shipping_template' => $shipping_template,
  206. 'goods_spec_format' => $goods_spec_format,
  207. 'goods_attr_format' => $goods_attr_format,
  208. 'introduction' => $introduction,
  209. 'keywords' => $keywords,
  210. 'unit' => $unit,
  211. 'sort' => $sort,
  212. 'commission_rate' => $commission_rate,
  213. 'video_url' => $video_url,
  214. 'goods_sku_data' => $goods_sku_data,
  215. 'goods_shop_category_ids' => $goods_shop_category_ids,
  216. 'supplier_id' => $supplier_id,
  217. 'pay_num1' => $pay_num1,
  218. 'price1' => $price1,
  219. 'pay_num2' => $pay_num2,
  220. 'price2' => $price2,
  221. 'pay_num3' => $pay_num3,
  222. 'price3' => $price3,
  223. 'province'=>$province,
  224. 'city'=>$city
  225. ];
  226. $res = $goods_model->addGoods($data);
  227. return $res;
  228. } else {
  229. //获取一级商品分类
  230. $goods_category_model = new GoodsCategoryModel();
  231. $condition = [
  232. [ 'pid', '=', 0 ]
  233. ];
  234. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
  235. $goods_category_list = $goods_category_list['data'];
  236. $this->assign("goods_category_list", $goods_category_list);
  237. //获取品牌;
  238. $goods_brand_model = new GoodsBrandModel();
  239. $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', 'in', ("0,$this->site_id") ] ], "brand_id, brand_name");
  240. $brand_list = $brand_list['data'];
  241. $this->assign("brand_list", $brand_list);
  242. //获取店内分类
  243. $goods_shop_category_model = new GoodsShopCategoryModel();
  244. $goods_shop_category_list = $goods_shop_category_model->getShopCategoryTree([ [ 'site_id', "=", $this->site_id ] ], 'category_id,category_name,pid,level');
  245. $goods_shop_category_list = $goods_shop_category_list['data'];
  246. $this->assign("goods_shop_category_list", $goods_shop_category_list);
  247. //获取运费模板
  248. $express_template_model = new ExpressTemplateModel();
  249. $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
  250. $express_template_list = $express_template_list['data'];
  251. $this->assign("express_template_list", $express_template_list);
  252. //获取商品类型
  253. $goods_attr_model = new GoodsAttributeModel();
  254. $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', 'in', ("0,$this->site_id") ] ], 'class_id,class_name');
  255. $attr_class_list = $attr_class_list['data'];
  256. $this->assign("attr_class_list", $attr_class_list);
  257. $is_install_supply = addon_is_exit("supply");
  258. if ($is_install_supply) {
  259. $supplier_model = new SupplierModel();
  260. $supplier_list = $supplier_model->getSupplierPageList([], 1, PAGE_LIST_ROWS, 'supplier_id DESC');
  261. $supplier_list = $supplier_list['data']['list'];
  262. $this->assign("supplier_list", $supplier_list);
  263. }
  264. $this->assign("is_install_supply", $is_install_supply);
  265. return $this->fetch("goods/add_goods");
  266. }
  267. }
  268. /**
  269. * 编辑商品
  270. * @return mixed
  271. */
  272. public function editGoods()
  273. {
  274. $goods_model = new GoodsModel();
  275. if (request()->isAjax()) {
  276. if ($this->shop_info["shop_status"] == 0) {
  277. return $goods_model->error([], "SHOP_IS_CLOSE");
  278. }
  279. $goods_id = input("goods_id", 0);// 商品id
  280. $goods_name = input("goods_name", "");// 商品名称
  281. $goods_attr_class = input("goods_attr_class", "");// 商品类型id
  282. $goods_attr_name = input("goods_attr_name", "");// 商品类型名称
  283. $category_id = input("category_id", 0);// 分类id
  284. $category_id_1 = input("category_id_1", 0);// 一级分类id
  285. $category_id_2 = input("category_id_2", 0);// 二级分类id
  286. $category_id_3 = input("category_id_3", 0);// 三级分类id
  287. $category_name = input("category_name", "");// 所属分类名称
  288. $commission_rate = input("commission_rate", 0);// 分佣比率(按照分类)
  289. $brand_id = input("brand_id", 0);// 品牌id
  290. $brand_name = input("brand_name", "");// 所属品牌名称
  291. $goods_shop_category_ids = input("goods_shop_category_ids", "");// 店内分类id,逗号隔开
  292. $goods_image = input("goods_image", "");// 商品主图路径
  293. $goods_content = input("goods_content", "");// 商品详情
  294. $goods_state = input("goods_state", "");// 商品状态(1.正常0下架)
  295. $goods_stock = input("goods_stock", 0);// 商品库存(总和)
  296. $goods_stock_alarm = input("goods_stock_alarm", 0);// 库存预警
  297. $is_free_shipping = input("is_free_shipping", 1);// 是否免邮
  298. $shipping_template = input("shipping_template", 0);// 指定运费模板
  299. $goods_spec_format = input("goods_spec_format", "");// 商品规格格式
  300. $goods_attr_format = input("goods_attr_format", "");// 商品属性格式
  301. $introduction = input("introduction", "");// 促销语
  302. $keywords = input("keywords", "");// 关键词
  303. $unit = input("unit", "");// 单位
  304. $sort = input("sort", 0);// 排序
  305. $video_url = input("video_url", "");// 视频
  306. $goods_sku_data = input("goods_sku_data", "");// SKU商品数据
  307. $supplier_id = input("supplier_id", "");// 供应商id
  308. $pay_num1 = input("pay_num1",0);
  309. $price1 = input("price1",0);
  310. $pay_num2 = input("pay_num2",0);
  311. $price2 =input("price2",0);
  312. $pay_num3 = input("pay_num3",0);
  313. $price3 = input("price3",0);
  314. //单规格需要
  315. $price = input("price", 0);// 商品价格(取第一个sku)
  316. $market_price = input("market_price", 0);// 市场价格(取第一个sku)
  317. $cost_price = input("cost_price", 0);// 成本价(取第一个sku)
  318. $sku_no = input("sku_no", "");// 商品sku编码
  319. $weight = input("weight", "");// 重量
  320. $volume = input("volume", "");// 体积
  321. $data = [
  322. 'goods_id' => $goods_id,
  323. 'goods_name' => $goods_name,
  324. 'goods_attr_class' => $goods_attr_class,
  325. 'goods_attr_name' => $goods_attr_name,
  326. 'site_id' => $this->site_id,
  327. 'category_id' => $category_id,
  328. 'category_id_1' => $category_id_1,
  329. 'category_id_2' => $category_id_2,
  330. 'category_id_3' => $category_id_3,
  331. 'category_name' => $category_name,
  332. 'brand_id' => $brand_id,
  333. 'brand_name' => $brand_name,
  334. 'goods_image' => $goods_image,
  335. 'goods_content' => $goods_content,
  336. 'goods_state' => $goods_state,
  337. 'price' => $price,
  338. 'market_price' => $market_price,
  339. 'cost_price' => $cost_price,
  340. 'sku_no' => $sku_no,
  341. 'weight' => $weight,
  342. 'volume' => $volume,
  343. 'goods_stock' => $goods_stock,
  344. 'goods_stock_alarm' => $goods_stock_alarm,
  345. 'is_free_shipping' => $is_free_shipping,
  346. 'shipping_template' => $shipping_template,
  347. 'goods_spec_format' => $goods_spec_format,
  348. 'goods_attr_format' => $goods_attr_format,
  349. 'introduction' => $introduction,
  350. 'keywords' => $keywords,
  351. 'unit' => $unit,
  352. 'sort' => $sort,
  353. 'commission_rate' => $commission_rate,
  354. 'video_url' => $video_url,
  355. 'goods_sku_data' => $goods_sku_data,
  356. 'goods_shop_category_ids' => $goods_shop_category_ids,
  357. 'supplier_id' => $supplier_id,
  358. 'pay_num1' => $pay_num1,
  359. 'price1' => $price1,
  360. 'pay_num2' => $pay_num2,
  361. 'price2' => $price2,
  362. 'pay_num3' => $pay_num3,
  363. 'price3' => $price3,
  364. ];
  365. $res = $goods_model->editGoods($data);
  366. return $res;
  367. } else {
  368. $goods_id = input("goods_id", 0);
  369. $goods_info = $goods_model->getGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ]);
  370. $goods_info = $goods_info['data'];
  371. $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");
  372. $goods_sku_list = $goods_sku_list['data'];
  373. $goods_info['sku_list'] = $goods_sku_list;
  374. $this->assign("goods_info", $goods_info);
  375. //获取一级商品分类
  376. $goods_category_model = new GoodsCategoryModel();
  377. $condition = [
  378. [ 'pid', '=', 0 ]
  379. ];
  380. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
  381. $goods_category_list = $goods_category_list['data'];
  382. $this->assign("goods_category_list", $goods_category_list);
  383. //获取品牌;
  384. $goods_brand_model = new GoodsBrandModel();
  385. $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', 'in', ("0,$this->site_id") ] ], "brand_id, brand_name");
  386. $brand_list = $brand_list['data'];
  387. $this->assign("brand_list", $brand_list);
  388. //获取店内分类
  389. $goods_shop_category_model = new GoodsShopCategoryModel();
  390. $goods_shop_category_list = $goods_shop_category_model->getShopCategoryTree([ [ 'site_id', "=", $this->site_id ] ], 'category_id,category_name,pid,level');
  391. $goods_shop_category_list = $goods_shop_category_list['data'];
  392. $this->assign("goods_shop_category_list", $goods_shop_category_list);
  393. //获取运费模板
  394. $express_template_model = new ExpressTemplateModel();
  395. $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
  396. $express_template_list = $express_template_list['data'];
  397. $this->assign("express_template_list", $express_template_list);
  398. //获取商品类型
  399. $goods_attr_model = new GoodsAttributeModel();
  400. $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', 'in', ("0,$this->site_id") ] ], 'class_id,class_name');
  401. $attr_class_list = $attr_class_list['data'];
  402. $this->assign("attr_class_list", $attr_class_list);
  403. $is_install_supply = addon_is_exit("supply");
  404. if ($is_install_supply) {
  405. $supplier_model = new SupplierModel();
  406. $supplier_list = $supplier_model->getSupplierPageList([], 1, PAGE_LIST_ROWS, 'supplier_id desc', 'supplier_id,title');
  407. $supplier_list = $supplier_list['data']['list'];
  408. $this->assign("supplier_list", $supplier_list);
  409. }
  410. $this->assign("is_install_supply", $is_install_supply);
  411. return $this->fetch("goods/edit_goods");
  412. }
  413. }
  414. /**
  415. * 删除商品
  416. */
  417. public function deleteGoods()
  418. {
  419. if (request()->isAjax()) {
  420. $goods_ids = input("goods_ids", 0);
  421. $goods_model = new GoodsModel();
  422. $res = $goods_model->modifyIsDelete($goods_ids, 1, $this->site_id);
  423. return $res;
  424. }
  425. }
  426. /**
  427. * 商品回收站
  428. */
  429. public function recycle()
  430. {
  431. if (request()->isAjax()) {
  432. $page_index = input('page', 1);
  433. $page_size = input('page_size', PAGE_LIST_ROWS);
  434. $search_keys = input('search_keys', "");
  435. $condition = [ [ 'is_delete', '=', 1 ], [ 'site_id', "=", $this->site_id ] ];
  436. if (!empty($search_keys)) {
  437. $condition[] = [ 'goods_name', 'like', '%' . $search_keys . '%' ];
  438. }
  439. $goods_model = new GoodsModel();
  440. $res = $goods_model->getGoodsPageList($condition, $page_index, $page_size);
  441. return $res;
  442. } else {
  443. return $this->fetch("goods/recycle");
  444. }
  445. }
  446. /**
  447. * 商品回收站商品删除
  448. */
  449. public function deleteRecycleGoods()
  450. {
  451. if (request()->isAjax()) {
  452. $goods_ids = input("goods_ids", 0);
  453. $goods_model = new GoodsModel();
  454. $res = $goods_model->deleteRecycleGoods($goods_ids, $this->site_id);
  455. return $res;
  456. }
  457. }
  458. /**
  459. * 商品回收站商品恢复
  460. */
  461. public function recoveryRecycle()
  462. {
  463. if (request()->isAjax()) {
  464. $goods_ids = input("goods_ids", 0);
  465. $goods_model = new GoodsModel();
  466. $res = $goods_model->modifyIsDelete($goods_ids, 0, $this->site_id);
  467. return $res;
  468. }
  469. }
  470. /**
  471. * 商品下架
  472. */
  473. public function offGoods()
  474. {
  475. if (request()->isAjax()) {
  476. $goods_ids = input("goods_ids", 0);
  477. $goods_state = input("goods_state", 0);
  478. $goods_model = new GoodsModel();
  479. $res = $goods_model->modifyGoodsState($goods_ids, $goods_state, $this->site_id);
  480. return $res;
  481. }
  482. }
  483. /**
  484. * 商品上架
  485. */
  486. public function onGoods()
  487. {
  488. if (request()->isAjax()) {
  489. $goods_ids = input("goods_ids", 0);
  490. $goods_state = input("goods_state", 0);
  491. $goods_model = new GoodsModel();
  492. $res = $goods_model->modifyGoodsState($goods_ids, $goods_state, $this->site_id);
  493. return $res;
  494. }
  495. }
  496. /**
  497. * 编辑商品库存
  498. * @return multitype:number unknown
  499. */
  500. public function editGoodsStock()
  501. {
  502. if (request()->isAjax()) {
  503. $sku_list = input("sku_list", '');
  504. $model = new GoodsModel;
  505. $res = $model->editGoodsStock($sku_list);
  506. return $res;
  507. }
  508. }
  509. /**
  510. * 获取商品分类列表
  511. * @return \multitype
  512. */
  513. public function getCategoryList()
  514. {
  515. if (request()->isAjax()) {
  516. $category_id = input("category_id", 0);
  517. $goods_category_model = new GoodsCategoryModel();
  518. $condition = [
  519. [ 'pid', '=', $category_id ]
  520. ];
  521. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
  522. return $goods_category_list;
  523. }
  524. }
  525. /**
  526. * 获取商品规格列表
  527. * @return \multitype
  528. */
  529. public function getSpecList()
  530. {
  531. if (request()->isAjax()) {
  532. $attr_id = input("attr_id", "");//排除已存在的规格项
  533. $search_text = input("search_text", "");
  534. $condition = [ [ 'is_spec', '=', 1 ], [ 'site_id', 'in', ("0,$this->site_id") ] ];
  535. if (!empty($attr_id)) {
  536. $condition[] = [ 'attr_id', 'not in', $attr_id ];
  537. }
  538. if (!empty($search_text)) {
  539. $condition[] = [ 'attr_name', 'like', '%' . $search_text . '%' ];
  540. }
  541. $goods_attr_model = new GoodsAttributeModel();
  542. $spec_list = $goods_attr_model->getSpecList($condition, 'attr_id,attr_name,attr_class_name', 'attr_id desc', PAGE_LIST_ROWS);
  543. return $spec_list;
  544. }
  545. }
  546. public function getSupplierPageList()
  547. {
  548. if (request()->isAjax()) {
  549. $is_install_supply = addon_is_exit("supply");
  550. if ($is_install_supply) {
  551. $supplier_model = new SupplierModel();
  552. $page_index = input('page_index', 1);
  553. $page_size = input('page_size', PAGE_LIST_ROWS);
  554. $search_text = input('search_text', '');
  555. $condition = [];
  556. if (!empty($search_text)) {
  557. $condition[] = [ 'title|desc|keywords|supplier_phone', 'LIKE', "%{$search_text}%" ];
  558. }
  559. $res = $supplier_model->getSupplierPageList($condition, $page_index, $page_size, 'supplier_id desc', 'supplier_id,title');
  560. return $res;
  561. }
  562. }
  563. }
  564. /**
  565. * 获取商品规格值列表
  566. * @return \multitype
  567. */
  568. public function getSpecValueList()
  569. {
  570. if (request()->isAjax()) {
  571. $attr_id = input("attr_id", 0);
  572. $search_text = input("search_text", "");
  573. $condition = [];
  574. if (!empty($attr_id)) {
  575. $condition[] = [ 'attr_id', '=', $attr_id ];
  576. }
  577. if (!empty($search_text)) {
  578. $condition[] = [ 'attr_value_name', 'like', '%' . $search_text . '%' ];
  579. }
  580. $goods_attr_model = new GoodsAttributeModel();
  581. $spec_list = $goods_attr_model->getSpecValueList($condition, 'attr_value_id,attr_value_name');
  582. return $spec_list;
  583. }
  584. }
  585. /**
  586. * 获取商品属性列表
  587. * @return \multitype
  588. */
  589. public function getAttributeList()
  590. {
  591. if (request()->isAjax()) {
  592. $goods_attr_model = new GoodsAttributeModel();
  593. $attr_class_id = input('attr_class_id', 0);// 商品类型id
  594. $attribute_list = $goods_attr_model->getAttributeList([ [ 'attr_class_id', '=', $attr_class_id ], [ 'is_spec', '=', 0 ], [ 'site_id', 'in', ("0,$this->site_id") ] ], 'attr_id,attr_name,attr_class_id,attr_class_name,attr_type,attr_value_format');
  595. if (!empty($attribute_list['data'])) {
  596. foreach ($attribute_list['data'] as $k => $v) {
  597. if (!empty($v['attr_value_format'])) {
  598. $attribute_list['data'][ $k ]['attr_value_format'] = json_decode($v['attr_value_format'], true);
  599. }
  600. }
  601. }
  602. return $attribute_list;
  603. }
  604. }
  605. /**
  606. * 获取SKU商品列表
  607. * @return \multitype
  608. */
  609. public function getGoodsSkuList()
  610. {
  611. if (request()->isAjax()) {
  612. $goods_id = input("goods_id", 0);
  613. $goods_model = new GoodsModel();
  614. $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');
  615. return $res;
  616. }
  617. }
  618. /**
  619. * 获取违规下架原因
  620. * @return \multitype
  621. */
  622. public function getVerifyStateRemark()
  623. {
  624. if (request()->isAjax()) {
  625. $goods_id = input("goods_id", 0);
  626. $goods_model = new GoodsModel();
  627. $res = $goods_model->getGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'verify_state', 'in', [ -2, 10 ] ], [ 'site_id', '=', $this->site_id ] ], 'verify_state_remark');
  628. return $res;
  629. }
  630. }
  631. /**
  632. * 商品选择组件
  633. * @return \multitype
  634. */
  635. public function goodsSelect()
  636. {
  637. if (request()->isAjax()) {
  638. $page = input('page', 1);
  639. $page_size = input('page_size', PAGE_LIST_ROWS);
  640. $goods_name = input('goods_name', '');
  641. $goods_id = input('goods_id', 0);
  642. $is_virtual = input('is_virtual', '');// 是否虚拟类商品(0实物1.虚拟)
  643. $condition = [
  644. [ 'is_delete', '=', 0 ],
  645. [ 'goods_state', '=', 1 ],
  646. [ 'verify_state', '=', 1 ],
  647. [ 'site_id', '=', $this->site_id ]
  648. ];
  649. if (!empty($goods_name)) {
  650. $condition[] = [ 'goods_name', 'like', '%' . $goods_name . '%' ];
  651. }
  652. if ($is_virtual !== "") {
  653. $condition[] = [ 'is_virtual', '=', $is_virtual ];
  654. }
  655. if (!empty($goods_id)) {
  656. $condition[] = [ 'goods_id', '=', $goods_id ];
  657. }
  658. $order = 'create_time desc';
  659. $goods_model = new GoodsModel();
  660. $field = 'goods_id,goods_name,goods_class_name,goods_image,price,goods_stock,sku_id,create_time,is_virtual';
  661. $goods_list = $goods_model->getGoodsPageList($condition, $page, $page_size, $order, $field);
  662. if (!empty($goods_list['data']['list'])) {
  663. foreach ($goods_list['data']['list'] as $k => $v) {
  664. $goods_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');
  665. $goods_sku_list = $goods_sku_list['data'];
  666. $goods_list['data']['list'][ $k ]['sku_list'] = $goods_sku_list;
  667. }
  668. }
  669. return $goods_list;
  670. } else {
  671. //已经选择的商品sku数据
  672. $select_id = input('select_id', '');
  673. $mode = input('mode', 'spu');
  674. $max_num = input('max_num', 0);
  675. $min_num = input('min_num', 0);
  676. $is_virtual = input('is_virtual', '');
  677. $disabled = input('disabled', 0);
  678. $this->assign('select_id', $select_id);
  679. $this->assign('mode', $mode);
  680. $this->assign('max_num', $max_num);
  681. $this->assign('min_num', $min_num);
  682. $this->assign('select_id', $select_id);
  683. $this->assign('is_virtual', $is_virtual);
  684. $this->assign('disabled', $disabled);
  685. return $this->fetch("goods/goods_select");
  686. }
  687. }
  688. /***********************************************************商品评价**************************************************/
  689. /**
  690. * 商品评价
  691. */
  692. public function evaluate()
  693. {
  694. $goods_evaluate = new GoodsEvaluateModel();
  695. if (request()->isAjax()) {
  696. $page_index = input('page', 1);
  697. $page_size = input('page_size', PAGE_LIST_ROWS);
  698. $explain_type = input('explain_type', ''); //1好评2中评3差评
  699. $is_show = input('is_show', ''); //1显示 0隐藏
  700. $search_text = input('search_text', ''); //搜索值
  701. $search_type = input('search_type', ''); //搜索类型
  702. $start_time = input('start_time', '');
  703. $end_time = input('end_time', '');
  704. $condition = [
  705. [ "site_id", "=", $this->site_id ]
  706. ];
  707. //评分类型
  708. if ($explain_type != "") {
  709. $condition[] = [ "explain_type", "=", $explain_type ];
  710. }
  711. if ($is_show != "") {
  712. $condition[] = [ "is_show", "=", $is_show ];
  713. }
  714. if ($search_text != "") {
  715. $condition[] = [ $search_type, "like", '%' . $search_text . '%' ];
  716. }
  717. if (!empty($start_time) && empty($end_time)) {
  718. $condition[] = [ "create_time", ">=", date_to_time($start_time) ];
  719. } elseif (empty($start_time) && !empty($end_time)) {
  720. $condition[] = [ "create_time", "<=", date_to_time($end_time) ];
  721. } elseif (!empty($start_time) && !empty($end_time)) {
  722. $condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  723. }
  724. return $goods_evaluate->getEvaluatePageList($condition, $page_index, $page_size, "create_time desc");
  725. } else {
  726. return $this->fetch("goods/evaluate");
  727. }
  728. }
  729. /**
  730. * 商品评价删除
  731. */
  732. public function deleteEvaluate()
  733. {
  734. if (request()->isAjax()) {
  735. $goods_evaluate = new GoodsEvaluateModel();
  736. $evaluate_id = input("evaluate_id", 0);
  737. return $goods_evaluate->deleteEvaluate($evaluate_id);
  738. }
  739. }
  740. /**
  741. * 商品推广
  742. * return
  743. */
  744. public function goodsUrl()
  745. {
  746. $goods_id = input('goods_id', '');
  747. $goods_model = new GoodsModel();
  748. $goods_sku_info = $goods_model->getGoodsSkuInfo([ [ 'goods_id', '=', $goods_id ] ], 'sku_id,goods_name');
  749. $goods_sku_info = $goods_sku_info['data'];
  750. $res = $goods_model->qrcode($goods_sku_info['sku_id'], $goods_sku_info['goods_name']);
  751. return $res;
  752. }
  753. /**
  754. * 商品预览
  755. * return
  756. */
  757. public function goodsPreview()
  758. {
  759. $goods_id = input('goods_id', '');
  760. $goods_model = new GoodsModel();
  761. $goods_sku_info = $goods_model->getGoodsSkuInfo([ [ 'goods_id', '=', $goods_id ] ], 'sku_id,goods_name');
  762. $goods_sku_info = $goods_sku_info['data'];
  763. $res = $goods_model->qrcode($goods_sku_info['sku_id'], $goods_sku_info['goods_name']);
  764. return $res;
  765. }
  766. /**
  767. * 商品评价回复
  768. */
  769. public function evaluateApply()
  770. {
  771. if (request()->isAjax()) {
  772. $goods_evaluate = new GoodsEvaluateModel();
  773. $evaluate_id = input("evaluate_id", 0);
  774. $explain = input("explain", 0);
  775. $is_first_explain = input("is_first_explain", 0);// 是否第一次回复
  776. $data = [
  777. 'evaluate_id' => $evaluate_id
  778. ];
  779. if ($is_first_explain == 0) {
  780. $data['explain_first'] = $explain;
  781. } elseif ($is_first_explain == 1) {
  782. $data['again_explain'] = $explain;
  783. }
  784. return $goods_evaluate->evaluateApply($data);
  785. }
  786. }
  787. }