Goods.php 31 KB

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