Goods.php 31 KB

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