Goods.php 10 KB

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