Goods.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <?php
  2. /**
  3. * 商品管理
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Goods extends AdminControl {
  21. public function initialize() {
  22. parent::initialize();
  23. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/goods.lang.php');
  24. }
  25. /**
  26. * 商品管理
  27. */
  28. public function index() {
  29. $goods_model = model('goods');
  30. /**
  31. * 处理商品分类
  32. */
  33. $choose_gcid = ($t = intval(input('param.choose_gcid'))) > 0 ? $t : 0;
  34. $gccache_arr = model('goodsclass')->getGoodsclassCache($choose_gcid, 3);
  35. View::assign('gc_json', json_encode($gccache_arr['showclass']));
  36. View::assign('gc_choose_json', json_encode($gccache_arr['choose_gcid']));
  37. /**
  38. * 查询条件
  39. */
  40. $where = array();
  41. $search_goods_name = trim(input('param.search_goods_name'));
  42. if ($search_goods_name != '') {
  43. $where[]=array('goods_name','like', '%' . $search_goods_name . '%');
  44. }
  45. $search_commonid = intval(input('param.search_commonid'));
  46. if ($search_commonid > 0) {
  47. $where[]=array('goods_commonid','=',$search_commonid);
  48. }
  49. $search_store_name = trim(input('param.search_store_name'));
  50. if ($search_store_name != '') {
  51. $where[]=array('store_name','like', '%' .$search_store_name . '%');
  52. }
  53. $b_id = intval(input('param.b_id'));
  54. if ($b_id > 0) {
  55. $where[]=array('brand_id','=',$b_id);
  56. }
  57. if ($choose_gcid > 0) {
  58. $where[] = array('gc_id_' . ($gccache_arr['showclass'][$choose_gcid]['depth']),'=',$choose_gcid);
  59. }
  60. $type = input('param.type');
  61. switch ($type) {
  62. // 禁售
  63. case 'lockup':
  64. $goods_list = $goods_model->getGoodsCommonLockUpList($where);
  65. break;
  66. // 等待审核
  67. case 'waitverify':
  68. $goods_list = $goods_model->getGoodsCommonWaitVerifyList($where, '*', 10, 'goods_verify desc, goods_commonid desc');
  69. break;
  70. // 全部商品
  71. default:
  72. //默认所有商品才有此参数
  73. $goods_state = input('param.goods_state');
  74. if (in_array($goods_state, array('0', '1', '10'))) {
  75. $where[]=array('goods_state','=',$goods_state);
  76. }
  77. $goods_verify = input('param.goods_verify');
  78. if (in_array($goods_verify, array('0', '1', '10'))) {
  79. $where[]=array('goods_verify','=',$goods_verify);
  80. }
  81. $goods_list = $goods_model->getGoodsCommonList($where, '*', 10, 'mall_goods_commend desc,mall_goods_sort asc');
  82. break;
  83. }
  84. View::assign('goods_list', $goods_list);
  85. View::assign('show_page', $goods_model->page_info->render());
  86. $storage_array = $goods_model->calculateStorage($goods_list);
  87. View::assign('storage_array', $storage_array);
  88. // 品牌
  89. $brand_list = model('brand')->getBrandPassedList(array());
  90. View::assign('search', $where);
  91. View::assign('brand_list', $brand_list);
  92. View::assign('state', array('1' => lang('goods_state_1'), '0' => lang('goods_state_0'), '10' => lang('goods_state_10')));
  93. View::assign('verify', array('1' => lang('goods_verify_1'), '0' => lang('goods_verify_0'), '10' => lang('goods_verify_10')));
  94. View::assign('ownShopIds', array_fill_keys(model('store')->getOwnShopIds(), true));
  95. $type = input('param.type');
  96. if(!in_array($type, array('lockup','waitverify','allgoods'))){
  97. $type = 'allgoods';
  98. }
  99. View::assign('type', $type);
  100. $this->setAdminCurItem($type);
  101. return View::fetch();
  102. }
  103. /**
  104. * 计算商品库存
  105. */
  106. public function goods_storage($goods_list) {
  107. $goods_model = model('goods');
  108. // 计算库存
  109. $storage_array = array();
  110. if (!empty($goods_list)) {
  111. foreach ($goods_list as $value) {
  112. $storage_array[$value['goods_commonid']]['goods_storage'] = $goods_model->getGoodsSum(array('goods_commonid'=>$value['goods_commonid']),'goods_storage');
  113. $storage_array[$value['goods_commonid']][] = $goods_model->getGoodsInfo(array('goods_commonid'=>$value['goods_commonid']),'goods_id');
  114. }
  115. return $storage_array;
  116. } else {
  117. return false;
  118. }
  119. }
  120. /**
  121. * 违规下架
  122. */
  123. public function goods_lockup() {
  124. if (request()->isPost()) {
  125. $commonids = input('param.commonids');
  126. $commonid_array = ds_delete_param($commonids);
  127. if ($commonid_array == FALSE) {
  128. $this->error(lang('ds_common_op_fail'));
  129. }
  130. $update = array();
  131. $update['goods_stateremark'] = trim(input('post.close_reason'));
  132. $where = array();
  133. $where[]=array('goods_commonid','in', $commonid_array);
  134. model('goods')->editProducesLockUp($update, $where);
  135. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  136. } else {
  137. View::assign('commonids', input('param.commonid'));
  138. echo View::fetch('close_remark');
  139. }
  140. }
  141. /**
  142. * 删除商品
  143. */
  144. public function goods_del() {
  145. $common_id = input('param.common_id');
  146. $common_id_array = ds_delete_param($common_id);
  147. if ($common_id_array == FALSE) {
  148. ds_json_encode('10001', lang('ds_common_op_fail'));
  149. }
  150. $condition = array();
  151. $condition[]=array('goods_commonid','in',$common_id_array);
  152. model('goods')->delGoodsAll($condition);
  153. ds_json_encode('10000', lang('ds_common_op_succ'));
  154. }
  155. /**
  156. * 审核商品
  157. */
  158. public function goods_verify() {
  159. if (request()->isPost()) {
  160. $commonids = input('param.commonids');
  161. $commonid_array = ds_delete_param($commonids);
  162. if ($commonid_array == FALSE) {
  163. $this->error(lang('ds_common_op_fail'));
  164. }
  165. $update2 = array();
  166. $update2['goods_verify'] = intval(input('param.verify_state'));
  167. $update1 = array();
  168. $update1['goods_verifyremark'] = trim(input('param.verify_reason'));
  169. $update1 = array_merge($update1, $update2);
  170. $where = array();
  171. $where[]=array('goods_commonid','in', $commonid_array);
  172. $goods_model = model('goods');
  173. if (intval(input('param.verify_state')) == 0) {
  174. $goods_model->editProducesVerifyFail($where, $update1, $update2);
  175. } else {
  176. $goods_model->editProduces($where, $update1, $update2);
  177. }
  178. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  179. } else {
  180. View::assign('commonids', input('param.commonid'));
  181. echo View::fetch('verify_remark');
  182. }
  183. }
  184. //ajax获取同一个commonid下面的商品信息
  185. public function get_goods_list_ajax() {
  186. $common_id = input('param.commonid');
  187. if (empty($common_id)) {
  188. $this->error(lang('param_error'));
  189. }
  190. $map['goods_commonid'] = $common_id;
  191. $goods_model = model('goods');
  192. $common_info = $goods_model->getGoodsCommonInfo($map,'spec_name');
  193. $goods_list = $goods_model->getGoodsList($map);
  194. //halt($goods_list);
  195. $spec_name = array_values((array) unserialize($common_info['spec_name']));
  196. foreach ($goods_list as $key => $val) {
  197. $goods_spec = array_values((array) unserialize($val['goods_spec']));
  198. $spec_array = array();
  199. foreach ($goods_spec as $k => $v) {
  200. $spec_array[] = '<div class="goods_spec">' . $spec_name[$k] . ':' . '<em title="' . $v . '">' . $v . '</em>' . '</div>';
  201. }
  202. $goods_list[$key]['goods_image'] = goods_cthumb($val['goods_image']);
  203. $goods_list[$key]['goods_spec'] = implode('', $spec_array);
  204. $goods_list[$key]['url'] = (string)url('home/Goods/index', array('goods_id' => $val['goods_id']));
  205. }
  206. return json_encode($goods_list);
  207. }
  208. /**
  209. * ajax操作
  210. */
  211. public function ajax() {
  212. $goods_model = model('goods');
  213. switch (input('param.branch')) {
  214. case 'mall_goods_commend':
  215. case 'mall_goods_sort':
  216. if (empty($result)) {
  217. $goods_model->editGoodsCommonById(array(trim(input('param.branch')) => trim(input('param.value'))),array(intval(input('param.id'))));
  218. echo 'true';
  219. exit;
  220. } else {
  221. echo 'false';
  222. exit;
  223. }
  224. break;
  225. }
  226. }
  227. /**
  228. * 获取卖家栏目列表,针对控制器下的栏目
  229. */
  230. protected function getAdminItemList() {
  231. $menu_array = array(
  232. array(
  233. 'name' => 'allgoods',
  234. 'text' => lang('goods_index_all_goods'),
  235. 'url' => (string)url('Goods/index')
  236. ),
  237. array(
  238. 'name' => 'lockup',
  239. 'text' => lang('goods_index_lock_goods'),
  240. 'url' => (string)url('Goods/index', ['type' => 'lockup'])
  241. ),
  242. array(
  243. 'name' => 'waitverify',
  244. 'text' => lang('goods_index_waitverify_goods'),
  245. 'url' => (string)url('Goods/index', ['type' => 'waitverify'])
  246. ),
  247. );
  248. return $menu_array;
  249. }
  250. }
  251. ?>