Goods.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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', "1");
  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");// 商品状态(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. $imgae = explode(',',$goods_image);
  181. if(count($imgae)>5){
  182. $res = $goods_model->count_image($imgae);
  183. return $res;
  184. }
  185. $data = [
  186. 'goods_name' => $goods_name,
  187. 'goods_attr_class' => $goods_attr_class,
  188. 'goods_attr_name' => $goods_attr_name,
  189. 'site_id' => $this->site_id,
  190. 'website_id' => $this->website_id,
  191. 'category_id' => $category_id,
  192. 'category_id_1' => $category_id_1,
  193. 'category_id_2' => $category_id_2,
  194. 'category_id_3' => $category_id_3,
  195. 'category_name' => $category_name,
  196. 'brand_id' => $brand_id,
  197. 'brand_name' => $brand_name,
  198. 'goods_image' => $goods_image,
  199. 'goods_content' => $goods_content,
  200. 'goods_state' => $goods_state,
  201. 'price' => $price,
  202. 'market_price' => $market_price,
  203. 'cost_price' => $cost_price,
  204. 'sku_no' => $sku_no,
  205. 'weight' => $weight,
  206. 'volume' => $volume,
  207. 'goods_stock' => $goods_stock,
  208. 'goods_stock_alarm' => $goods_stock_alarm,
  209. 'is_free_shipping' => $is_free_shipping,
  210. 'shipping_template' => $shipping_template,
  211. 'goods_spec_format' => $goods_spec_format,
  212. 'goods_attr_format' => $goods_attr_format,
  213. 'introduction' => $introduction,
  214. 'keywords' => $keywords,
  215. 'unit' => $unit,
  216. 'sort' => $sort,
  217. 'commission_rate' => $commission_rate,
  218. 'video_url' => $video_url,
  219. 'goods_sku_data' => $goods_sku_data,
  220. 'goods_shop_category_ids' => $goods_shop_category_ids,
  221. 'supplier_id' => $supplier_id,
  222. 'pay_num1' => $pay_num1,
  223. 'price1' => $price1,
  224. 'pay_num2' => $pay_num2,
  225. 'price2' => $price2,
  226. 'pay_num3' => $pay_num3,
  227. 'price3' => $price3,
  228. 'province'=>$province,
  229. 'city'=>$city
  230. ];
  231. $res = $goods_model->addGoods($data);
  232. return $res;
  233. } else {
  234. //获取一级商品分类
  235. $goods_category_model = new GoodsCategoryModel();
  236. $condition = [
  237. [ 'pid', '=', 0 ]
  238. ];
  239. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
  240. $goods_category_list = $goods_category_list['data'];
  241. $this->assign("goods_category_list", $goods_category_list);
  242. $shop_model = new \app\model\shop\Shop();
  243. $shop_brand_id = $shop_model->getShopInfo([['site_id','=',$this->site_id]],'brand_id');
  244. //获取品牌;
  245. $goods_brand_model = new GoodsBrandModel();
  246. $brand_list = $goods_brand_model->getBrandList([], "brand_id, brand_name");
  247. $brand_list = $brand_list['data'];
  248. $this->assign("brand_list", $brand_list);
  249. //获取店内分类
  250. $goods_shop_category_model = new GoodsShopCategoryModel();
  251. $goods_shop_category_list = $goods_shop_category_model->getShopCategoryTree([ [ 'site_id', "=", $this->site_id ] ], 'category_id,category_name,pid,level');
  252. $goods_shop_category_list = $goods_shop_category_list['data'];
  253. $this->assign("goods_shop_category_list", $goods_shop_category_list);
  254. //获取运费模板
  255. $express_template_model = new ExpressTemplateModel();
  256. $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
  257. $express_template_list = $express_template_list['data'];
  258. $this->assign("express_template_list", $express_template_list);
  259. //获取商品类型
  260. $goods_attr_model = new GoodsAttributeModel();
  261. $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', 'in', ("0,$this->site_id") ] ], 'class_id,class_name');
  262. $attr_class_list = $attr_class_list['data'];
  263. $this->assign("attr_class_list", $attr_class_list);
  264. $is_install_supply = addon_is_exit("supply");
  265. if ($is_install_supply) {
  266. $supplier_model = new SupplierModel();
  267. $supplier_list = $supplier_model->getSupplierPageList([], 1, PAGE_LIST_ROWS, 'supplier_id DESC');
  268. $supplier_list = $supplier_list['data']['list'];
  269. $this->assign("supplier_list", $supplier_list);
  270. }
  271. $this->assign("is_install_supply", $is_install_supply);
  272. return $this->fetch("goods/add_goods");
  273. }
  274. }
  275. /**
  276. * 编辑商品
  277. * @return mixed
  278. */
  279. public function editGoods()
  280. {
  281. $goods_model = new GoodsModel();
  282. if (request()->isAjax()) {
  283. if ($this->shop_info["shop_status"] == 0) {
  284. return $goods_model->error([], "SHOP_IS_CLOSE");
  285. }
  286. $goods_id = input("goods_id", 0);// 商品id
  287. $goods_name = input("goods_name", "");// 商品名称
  288. $goods_attr_class = input("goods_attr_class", "");// 商品类型id
  289. $goods_attr_name = input("goods_attr_name", "");// 商品类型名称
  290. $category_id = input("category_id", 0);// 分类id
  291. $category_id_1 = input("category_id_1", 0);// 一级分类id
  292. $category_id_2 = input("category_id_2", 0);// 二级分类id
  293. $category_id_3 = input("category_id_3", 0);// 三级分类id
  294. $category_name = input("category_name", "");// 所属分类名称
  295. $commission_rate = input("commission_rate", 0);// 分佣比率(按照分类)
  296. $brand_id = input("brand_id", 0);// 品牌id
  297. $brand_name = input("brand_name", "");// 所属品牌名称
  298. $goods_shop_category_ids = input("goods_shop_category_ids", "");// 店内分类id,逗号隔开
  299. $goods_image = input("goods_image", "");// 商品主图路径
  300. $goods_content = input("goods_content", "");// 商品详情
  301. $goods_state = input("goods_state", "");// 商品状态(1.正常0下架)
  302. $goods_stock = input("goods_stock", 0);// 商品库存(总和)
  303. $goods_stock_alarm = input("goods_stock_alarm", 0);// 库存预警
  304. $is_free_shipping = input("is_free_shipping", 1);// 是否免邮
  305. $shipping_template = input("shipping_template", 0);// 指定运费模板
  306. $goods_spec_format = input("goods_spec_format", "");// 商品规格格式
  307. $goods_attr_format = input("goods_attr_format", "");// 商品属性格式
  308. $introduction = input("introduction", "");// 促销语
  309. $keywords = input("keywords", "");// 关键词
  310. $unit = input("unit", "");// 单位
  311. $sort = input("sort", 0);// 排序
  312. $video_url = input("video_url", "");// 视频
  313. $goods_sku_data = input("goods_sku_data", "");// SKU商品数据
  314. $supplier_id = input("supplier_id", "");// 供应商id
  315. $pay_num1 = input("pay_num1",0);
  316. $price1 = input("price1",0);
  317. $pay_num2 = input("pay_num2",0);
  318. $price2 =input("price2",0);
  319. $pay_num3 = input("pay_num3",0);
  320. $price3 = input("price3",0);
  321. //单规格需要
  322. $price = input("price", 0);// 商品价格(取第一个sku)
  323. $market_price = input("market_price", 0);// 市场价格(取第一个sku)
  324. $cost_price = input("cost_price", 0);// 成本价(取第一个sku)
  325. $sku_no = input("sku_no", "");// 商品sku编码
  326. $weight = input("weight", "");// 重量
  327. $volume = input("volume", "");// 体积
  328. $imgae = explode(',',$goods_image);
  329. if(count($imgae)>5){
  330. $res = $goods_model->count_image($imgae);
  331. return $res;
  332. }
  333. $data = [
  334. 'goods_id' => $goods_id,
  335. 'goods_name' => $goods_name,
  336. 'goods_attr_class' => $goods_attr_class,
  337. 'goods_attr_name' => $goods_attr_name,
  338. 'site_id' => $this->site_id,
  339. 'category_id' => $category_id,
  340. 'category_id_1' => $category_id_1,
  341. 'category_id_2' => $category_id_2,
  342. 'category_id_3' => $category_id_3,
  343. 'category_name' => $category_name,
  344. 'brand_id' => $brand_id,
  345. 'brand_name' => $brand_name,
  346. 'goods_image' => $goods_image,
  347. 'goods_content' => $goods_content,
  348. 'goods_state' => $goods_state,
  349. 'price' => $price,
  350. 'market_price' => $market_price,
  351. 'cost_price' => $cost_price,
  352. 'sku_no' => $sku_no,
  353. 'weight' => $weight,
  354. 'volume' => $volume,
  355. 'goods_stock' => $goods_stock,
  356. 'goods_stock_alarm' => $goods_stock_alarm,
  357. 'is_free_shipping' => $is_free_shipping,
  358. 'shipping_template' => $shipping_template,
  359. 'goods_spec_format' => $goods_spec_format,
  360. 'goods_attr_format' => $goods_attr_format,
  361. 'introduction' => $introduction,
  362. 'keywords' => $keywords,
  363. 'unit' => $unit,
  364. 'sort' => $sort,
  365. 'commission_rate' => $commission_rate,
  366. 'video_url' => $video_url,
  367. 'goods_sku_data' => $goods_sku_data,
  368. 'goods_shop_category_ids' => $goods_shop_category_ids,
  369. 'supplier_id' => $supplier_id,
  370. 'pay_num1' => $pay_num1,
  371. 'price1' => $price1,
  372. 'pay_num2' => $pay_num2,
  373. 'price2' => $price2,
  374. 'pay_num3' => $pay_num3,
  375. 'price3' => $price3,
  376. ];
  377. $res = $goods_model->editGoods($data);
  378. return $res;
  379. } else {
  380. $goods_id = input("goods_id", 0);
  381. $goods_info = $goods_model->getGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ]);
  382. $goods_info = $goods_info['data'];
  383. $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");
  384. $goods_sku_list = $goods_sku_list['data'];
  385. $goods_info['sku_list'] = $goods_sku_list;
  386. $this->assign("goods_info", $goods_info);
  387. //获取一级商品分类
  388. $goods_category_model = new GoodsCategoryModel();
  389. $condition = [
  390. [ 'pid', '=', 0 ]
  391. ];
  392. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
  393. $goods_category_list = $goods_category_list['data'];
  394. $this->assign("goods_category_list", $goods_category_list);
  395. $shop_model = new \app\model\shop\Shop();
  396. $shop_brand_id = $shop_model->getShopInfo([['site_id','=',$this->site_id]],'brand_id');
  397. //获取品牌;
  398. $goods_brand_model = new GoodsBrandModel();
  399. $brand_list = $goods_brand_model->getBrandList([], "brand_id, brand_name");
  400. $brand_list = $brand_list['data'];
  401. $this->assign("brand_list", $brand_list);
  402. //获取店内分类
  403. $goods_shop_category_model = new GoodsShopCategoryModel();
  404. $goods_shop_category_list = $goods_shop_category_model->getShopCategoryTree([ [ 'site_id', "=", $this->site_id ] ], 'category_id,category_name,pid,level');
  405. $goods_shop_category_list = $goods_shop_category_list['data'];
  406. $this->assign("goods_shop_category_list", $goods_shop_category_list);
  407. //获取运费模板
  408. $express_template_model = new ExpressTemplateModel();
  409. $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
  410. $express_template_list = $express_template_list['data'];
  411. $this->assign("express_template_list", $express_template_list);
  412. //获取商品类型
  413. $goods_attr_model = new GoodsAttributeModel();
  414. $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', 'in', ("0,$this->site_id") ] ], 'class_id,class_name');
  415. $attr_class_list = $attr_class_list['data'];
  416. $this->assign("attr_class_list", $attr_class_list);
  417. $is_install_supply = addon_is_exit("supply");
  418. if ($is_install_supply) {
  419. $supplier_model = new SupplierModel();
  420. $supplier_list = $supplier_model->getSupplierPageList([], 1, PAGE_LIST_ROWS, 'supplier_id desc', 'supplier_id,title');
  421. $supplier_list = $supplier_list['data']['list'];
  422. $this->assign("supplier_list", $supplier_list);
  423. }
  424. $this->assign("is_install_supply", $is_install_supply);
  425. return $this->fetch("goods/edit_goods");
  426. }
  427. }
  428. /**
  429. * 删除商品
  430. */
  431. public function deleteGoods()
  432. {
  433. if (request()->isAjax()) {
  434. $goods_ids = input("goods_ids", 0);
  435. $goods_model = new GoodsModel();
  436. $res = $goods_model->modifyIsDelete($goods_ids, 1, $this->site_id);
  437. return $res;
  438. }
  439. }
  440. /**
  441. * 商品回收站
  442. */
  443. public function recycle()
  444. {
  445. if (request()->isAjax()) {
  446. $page_index = input('page', 1);
  447. $page_size = input('page_size', PAGE_LIST_ROWS);
  448. $search_keys = input('search_keys', "");
  449. $condition = [ [ 'is_delete', '=', 1 ], [ 'site_id', "=", $this->site_id ] ];
  450. if (!empty($search_keys)) {
  451. $condition[] = [ 'goods_name', 'like', '%' . $search_keys . '%' ];
  452. }
  453. $goods_model = new GoodsModel();
  454. $res = $goods_model->getGoodsPageList($condition, $page_index, $page_size);
  455. return $res;
  456. } else {
  457. return $this->fetch("goods/recycle");
  458. }
  459. }
  460. /**
  461. * 商品回收站商品删除
  462. */
  463. public function deleteRecycleGoods()
  464. {
  465. if (request()->isAjax()) {
  466. $goods_ids = input("goods_ids", 0);
  467. $goods_model = new GoodsModel();
  468. $res = $goods_model->deleteRecycleGoods($goods_ids, $this->site_id);
  469. return $res;
  470. }
  471. }
  472. /**
  473. * 商品回收站商品恢复
  474. */
  475. public function recoveryRecycle()
  476. {
  477. if (request()->isAjax()) {
  478. $goods_ids = input("goods_ids", 0);
  479. $goods_model = new GoodsModel();
  480. $res = $goods_model->modifyIsDelete($goods_ids, 0, $this->site_id);
  481. return $res;
  482. }
  483. }
  484. /**
  485. * 商品下架
  486. */
  487. public function offGoods()
  488. {
  489. if (request()->isAjax()) {
  490. $goods_ids = input("goods_ids", 0);
  491. $goods_state = input("goods_state", 0);
  492. $goods_model = new GoodsModel();
  493. $res = $goods_model->modifyGoodsState($goods_ids, $goods_state, $this->site_id);
  494. return $res;
  495. }
  496. }
  497. /**
  498. * 商品上架
  499. */
  500. public function onGoods()
  501. {
  502. if (request()->isAjax()) {
  503. $goods_ids = input("goods_ids", 0);
  504. $goods_state = input("goods_state", 0);
  505. $goods_model = new GoodsModel();
  506. $res = $goods_model->modifyGoodsState($goods_ids, $goods_state, $this->site_id);
  507. return $res;
  508. }
  509. }
  510. /**
  511. * 编辑商品库存
  512. * @return multitype:number unknown
  513. */
  514. public function editGoodsStock()
  515. {
  516. if (request()->isAjax()) {
  517. $sku_list = input("sku_list", '');
  518. $model = new GoodsModel;
  519. $res = $model->editGoodsStock($sku_list);
  520. return $res;
  521. }
  522. }
  523. /**
  524. * 获取商品分类列表
  525. * @return \multitype
  526. */
  527. public function getCategoryList()
  528. {
  529. if (request()->isAjax()) {
  530. $category_id = input("category_id", 0);
  531. $goods_category_model = new GoodsCategoryModel();
  532. $condition = [
  533. [ 'pid', '=', $category_id ]
  534. ];
  535. $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
  536. return $goods_category_list;
  537. }
  538. }
  539. /**
  540. * 获取商品规格列表
  541. * @return \multitype
  542. */
  543. public function getSpecList()
  544. {
  545. if (request()->isAjax()) {
  546. $attr_id = input("attr_id", "");//排除已存在的规格项
  547. $search_text = input("search_text", "");
  548. $condition = [ [ 'is_spec', '=', 1 ], [ 'site_id', 'in', ("0,$this->site_id") ] ];
  549. if (!empty($attr_id)) {
  550. $condition[] = [ 'attr_id', 'not in', $attr_id ];
  551. }
  552. if (!empty($search_text)) {
  553. $condition[] = [ 'attr_name', 'like', '%' . $search_text . '%' ];
  554. }
  555. $goods_attr_model = new GoodsAttributeModel();
  556. $spec_list = $goods_attr_model->getSpecList($condition, 'attr_id,attr_name,attr_class_name', 'attr_id desc', PAGE_LIST_ROWS);
  557. return $spec_list;
  558. }
  559. }
  560. public function getSupplierPageList()
  561. {
  562. if (request()->isAjax()) {
  563. $is_install_supply = addon_is_exit("supply");
  564. if ($is_install_supply) {
  565. $supplier_model = new SupplierModel();
  566. $page_index = input('page_index', 1);
  567. $page_size = input('page_size', PAGE_LIST_ROWS);
  568. $search_text = input('search_text', '');
  569. $condition = [];
  570. if (!empty($search_text)) {
  571. $condition[] = [ 'title|desc|keywords|supplier_phone', 'LIKE', "%{$search_text}%" ];
  572. }
  573. $res = $supplier_model->getSupplierPageList($condition, $page_index, $page_size, 'supplier_id desc', 'supplier_id,title');
  574. return $res;
  575. }
  576. }
  577. }
  578. /**
  579. * 获取商品规格值列表
  580. * @return \multitype
  581. */
  582. public function getSpecValueList()
  583. {
  584. if (request()->isAjax()) {
  585. $attr_id = input("attr_id", 0);
  586. $search_text = input("search_text", "");
  587. $condition = [];
  588. if (!empty($attr_id)) {
  589. $condition[] = [ 'attr_id', '=', $attr_id ];
  590. }
  591. if (!empty($search_text)) {
  592. $condition[] = [ 'attr_value_name', 'like', '%' . $search_text . '%' ];
  593. }
  594. $goods_attr_model = new GoodsAttributeModel();
  595. $spec_list = $goods_attr_model->getSpecValueList($condition, 'attr_value_id,attr_value_name');
  596. return $spec_list;
  597. }
  598. }
  599. /**
  600. * 获取商品属性列表
  601. * @return \multitype
  602. */
  603. public function getAttributeList()
  604. {
  605. if (request()->isAjax()) {
  606. $goods_attr_model = new GoodsAttributeModel();
  607. $attr_class_id = input('attr_class_id', 0);// 商品类型id
  608. $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');
  609. if (!empty($attribute_list['data'])) {
  610. foreach ($attribute_list['data'] as $k => $v) {
  611. if (!empty($v['attr_value_format'])) {
  612. $attribute_list['data'][ $k ]['attr_value_format'] = json_decode($v['attr_value_format'], true);
  613. }
  614. }
  615. }
  616. return $attribute_list;
  617. }
  618. }
  619. /**
  620. * 获取SKU商品列表
  621. * @return \multitype
  622. */
  623. public function getGoodsSkuList()
  624. {
  625. if (request()->isAjax()) {
  626. $goods_id = input("goods_id", 0);
  627. $goods_model = new GoodsModel();
  628. $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');
  629. return $res;
  630. }
  631. }
  632. /**
  633. * 获取违规下架原因
  634. * @return \multitype
  635. */
  636. public function getVerifyStateRemark()
  637. {
  638. if (request()->isAjax()) {
  639. $goods_id = input("goods_id", 0);
  640. $goods_model = new GoodsModel();
  641. $res = $goods_model->getGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'verify_state', 'in', [ -2, 10 ] ], [ 'site_id', '=', $this->site_id ] ], 'verify_state_remark');
  642. return $res;
  643. }
  644. }
  645. /**
  646. * 商品选择组件
  647. * @return \multitype
  648. */
  649. public function goodsSelect()
  650. {
  651. if (request()->isAjax()) {
  652. $page = input('page', 1);
  653. $page_size = input('page_size', PAGE_LIST_ROWS);
  654. $goods_name = input('goods_name', '');
  655. $goods_id = input('goods_id', 0);
  656. $is_virtual = input('is_virtual', '');// 是否虚拟类商品(0实物1.虚拟)
  657. $condition = [
  658. [ 'is_delete', '=', 0 ],
  659. [ 'goods_state', '=', 1 ],
  660. [ 'verify_state', '=', 1 ],
  661. [ 'site_id', '=', $this->site_id ]
  662. ];
  663. if (!empty($goods_name)) {
  664. $condition[] = [ 'goods_name', 'like', '%' . $goods_name . '%' ];
  665. }
  666. if ($is_virtual !== "") {
  667. $condition[] = [ 'is_virtual', '=', $is_virtual ];
  668. }
  669. if (!empty($goods_id)) {
  670. $condition[] = [ 'goods_id', '=', $goods_id ];
  671. }
  672. $order = 'create_time desc';
  673. $goods_model = new GoodsModel();
  674. $field = 'goods_id,goods_name,goods_class_name,goods_image,price,goods_stock,sku_id,create_time,is_virtual';
  675. $goods_list = $goods_model->getGoodsPageList($condition, $page, $page_size, $order, $field);
  676. if (!empty($goods_list['data']['list'])) {
  677. foreach ($goods_list['data']['list'] as $k => $v) {
  678. $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');
  679. $goods_sku_list = $goods_sku_list['data'];
  680. $goods_list['data']['list'][ $k ]['sku_list'] = $goods_sku_list;
  681. }
  682. }
  683. return $goods_list;
  684. } else {
  685. //已经选择的商品sku数据
  686. $select_id = input('select_id', '');
  687. $mode = input('mode', 'spu');
  688. $max_num = input('max_num', 0);
  689. $min_num = input('min_num', 0);
  690. $is_virtual = input('is_virtual', '');
  691. $disabled = input('disabled', 0);
  692. $this->assign('select_id', $select_id);
  693. $this->assign('mode', $mode);
  694. $this->assign('max_num', $max_num);
  695. $this->assign('min_num', $min_num);
  696. $this->assign('select_id', $select_id);
  697. $this->assign('is_virtual', $is_virtual);
  698. $this->assign('disabled', $disabled);
  699. return $this->fetch("goods/goods_select");
  700. }
  701. }
  702. /***********************************************************商品评价**************************************************/
  703. /**
  704. * 商品评价
  705. */
  706. public function evaluate()
  707. {
  708. $goods_evaluate = new GoodsEvaluateModel();
  709. if (request()->isAjax()) {
  710. $page_index = input('page', 1);
  711. $page_size = input('page_size', PAGE_LIST_ROWS);
  712. $explain_type = input('explain_type', ''); //1好评2中评3差评
  713. $is_show = input('is_show', ''); //1显示 0隐藏
  714. $search_text = input('search_text', ''); //搜索值
  715. $search_type = input('search_type', ''); //搜索类型
  716. $start_time = input('start_time', '');
  717. $end_time = input('end_time', '');
  718. $condition = [
  719. [ "site_id", "=", $this->site_id ]
  720. ];
  721. //评分类型
  722. if ($explain_type != "") {
  723. $condition[] = [ "explain_type", "=", $explain_type ];
  724. }
  725. if ($is_show != "") {
  726. $condition[] = [ "is_show", "=", $is_show ];
  727. }
  728. if ($search_text != "") {
  729. $condition[] = [ $search_type, "like", '%' . $search_text . '%' ];
  730. }
  731. if (!empty($start_time) && empty($end_time)) {
  732. $condition[] = [ "create_time", ">=", date_to_time($start_time) ];
  733. } elseif (empty($start_time) && !empty($end_time)) {
  734. $condition[] = [ "create_time", "<=", date_to_time($end_time) ];
  735. } elseif (!empty($start_time) && !empty($end_time)) {
  736. $condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
  737. }
  738. return $goods_evaluate->getEvaluatePageList($condition, $page_index, $page_size, "create_time desc");
  739. } else {
  740. return $this->fetch("goods/evaluate");
  741. }
  742. }
  743. /**
  744. * 商品评价删除
  745. */
  746. public function deleteEvaluate()
  747. {
  748. if (request()->isAjax()) {
  749. $goods_evaluate = new GoodsEvaluateModel();
  750. $evaluate_id = input("evaluate_id", 0);
  751. return $goods_evaluate->deleteEvaluate($evaluate_id);
  752. }
  753. }
  754. /**
  755. * 商品推广
  756. * return
  757. */
  758. public function goodsUrl()
  759. {
  760. $goods_id = input('goods_id', '');
  761. $goods_model = new GoodsModel();
  762. $goods_sku_info = $goods_model->getGoodsSkuInfo([ [ 'goods_id', '=', $goods_id ] ], 'sku_id,goods_name');
  763. $goods_sku_info = $goods_sku_info['data'];
  764. $res = $goods_model->qrcode($goods_sku_info['sku_id'], $goods_sku_info['goods_name']);
  765. return $res;
  766. }
  767. /**
  768. * 商品预览
  769. * return
  770. */
  771. public function goodsPreview()
  772. {
  773. $goods_id = input('goods_id', '');
  774. $goods_model = new GoodsModel();
  775. $goods_sku_info = $goods_model->getGoodsSkuInfo([ [ 'goods_id', '=', $goods_id ] ], 'sku_id,goods_name');
  776. $goods_sku_info = $goods_sku_info['data'];
  777. $res = $goods_model->qrcode($goods_sku_info['sku_id'], $goods_sku_info['goods_name']);
  778. return $res;
  779. }
  780. /**
  781. * 商品评价回复
  782. */
  783. public function evaluateApply()
  784. {
  785. if (request()->isAjax()) {
  786. $goods_evaluate = new GoodsEvaluateModel();
  787. $evaluate_id = input("evaluate_id", 0);
  788. $explain = input("explain", 0);
  789. $is_first_explain = input("is_first_explain", 0);// 是否第一次回复
  790. $data = [
  791. 'evaluate_id' => $evaluate_id
  792. ];
  793. if ($is_first_explain == 0) {
  794. $data['explain_first'] = $explain;
  795. } elseif ($is_first_explain == 1) {
  796. $data['again_explain'] = $explain;
  797. }
  798. return $goods_evaluate->evaluateApply($data);
  799. }
  800. }
  801. }