Manage.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?php
  2. namespace Goods\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function search_api()
  7. {
  8. $table = 'goods/info';
  9. $keyword = Dever::input('keyword');
  10. $yes = Dever::input('yes');
  11. $where = array();
  12. $cate = Dever::input('cate');
  13. if ($cate) {
  14. $where['cate_id'] = $cate;
  15. }
  16. if ($yes) {
  17. $yes = Dever::db($table)->search(array('ids' => $yes));
  18. }
  19. if (!$keyword) {
  20. $where['limit'] = '0,50';
  21. $data = Dever::db($table)->search($where);
  22. } else {
  23. $where['name'] = $keyword;
  24. $data = Dever::db($table)->search($where);
  25. }
  26. $result = array();
  27. if ($yes) {
  28. foreach ($yes as $k => $v) {
  29. if (isset($data[$k])) {
  30. unset($data[$k]);
  31. }
  32. $yes[$k]['selected'] = 'selected';
  33. }
  34. $data = $yes + $data;
  35. $data = array_merge($data, array());
  36. } else {
  37. $data = array_merge($data, array());
  38. }
  39. if (!$data) {
  40. Dever::alert('暂无数据');
  41. }
  42. return $data;
  43. }
  44. /**
  45. * 更新信息
  46. *
  47. * @return mixed
  48. */
  49. public function infoUpdate($id, $name, $data)
  50. {
  51. # 更新分类id
  52. $category = Dever::param('category', $data);
  53. if ($category) {
  54. if (is_array($category)) {
  55. $category_id = end($category);
  56. $top_category_id = $category[0];
  57. if (isset($category[1])) {
  58. $second_category_id = $category[1];
  59. } else {
  60. $second_category_id = $category[0];
  61. }
  62. } else {
  63. $category_id = $category;
  64. $top_category_id = $category;
  65. $second_category_id = $category;
  66. }
  67. $update['top_category_id'] = $top_category_id;
  68. $update['second_category_id'] = $second_category_id;
  69. $update['category_id'] = $category_id;
  70. }
  71. $pic = Dever::param('pic', $data);
  72. $pic_cover = Dever::param('pic_cover', $data);
  73. if ($pic && !$pic_cover) {
  74. if (is_string($pic)) {
  75. $pic = explode(',', $pic);
  76. }
  77. $update['pic_cover'] = $pic[0];
  78. }
  79. if (isset($update)) {
  80. $update['where_id'] = $id;
  81. Dever::db('goods/info')->update($update);
  82. }
  83. }
  84. /**
  85. * 更新需求属性信息
  86. *
  87. * @return mixed
  88. */
  89. public function attrUpdate($id, $name, $data)
  90. {
  91. print_r($data);die;
  92. foreach ($data as $k => $v) {
  93. }
  94. }
  95. /**
  96. * 显示信息
  97. *
  98. * @return mixed
  99. */
  100. public function info($id)
  101. {
  102. $info = Dever::db('goods/info')->one($id);
  103. if ($info) {
  104. $table['编号'] = $info['id'];
  105. $table['标题'] = $info['name'];
  106. $table['分类'] = Dever::load("category/api.string", $info['category']);
  107. if ($info['pic']) {
  108. $table['商品图'] = '<img src="'.$info['pic'].'" width="150" />';
  109. }
  110. //$table['属性'] = $this->attrInfo($info);
  111. if ($info['cdate']) {
  112. $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']);
  113. }
  114. if ($info['udate']) {
  115. $table['更新时间'] = date("Y-m-d H:i:s", $info['udate']);
  116. }
  117. }
  118. return Dever::table($table);
  119. }
  120. private function attrInfo($info)
  121. {
  122. $table = array();
  123. $info = Info::init($info['top_category_id']);
  124. if ($info) {
  125. $info = $info->info($info, 'id');
  126. if ($info && isset($info['attr'])) {
  127. foreach ($info['attr'] as $k => $v) {
  128. $table[$v['name']] = $v['value_string'];
  129. }
  130. }
  131. }
  132. return Dever::table($table);
  133. }
  134. public function area($id, $name, $data)
  135. {
  136. # 不再执行syncone等后续操作
  137. Dever::config('base')->after = 1;
  138. $type = Dever::input('type');
  139. $area = Dever::param('area', $data);
  140. if ($area) {
  141. if (isset($area[2])) {
  142. $update['district_id'] = $area[2];
  143. }
  144. if (isset($area[1])) {
  145. $update['city_id'] = $area[1];
  146. }
  147. if (isset($area[0])) {
  148. $update['province_id'] = $area[0];
  149. }
  150. if (isset($update)) {
  151. $update['where_id'] = $id;
  152. Dever::db($type . '/info')->update($update);
  153. }
  154. }
  155. }
  156. public function skuConfig()
  157. {
  158. $data['action'] = Dever::url('goods/lib/manage.skuUp');
  159. $data['info_id'] = Dever::input('search_option_info_id');
  160. return $data;
  161. }
  162. public function skuUp_api()
  163. {
  164. $info_id = Dever::input('info_id');
  165. $attr = Dever::input('attr');
  166. $key = Dever::input('key');
  167. $price = Dever::input('price');
  168. $s_price = Dever::input('s_price');
  169. $num = Dever::input('num');
  170. if ($key) {
  171. foreach ($key as $k => $v) {
  172. if (isset($price[$k]) && $price[$k]) {
  173. $info = Dever::db('goods/info_sku')->one(array('key' => $v));
  174. $data['info_id'] = $info_id;
  175. $data['attr'] = $attr[$k];
  176. $data['key'] = $v;
  177. $data['price'] = $price[$k];
  178. $data['s_price'] = $s_price[$k];
  179. $data['num'] = $num[$k];
  180. if (!$info) {
  181. Dever::db('goods/info_sku')->insert($data);
  182. } else {
  183. $data['where_id'] = $info['id'];
  184. Dever::db('goods/info_sku')->update($data);
  185. }
  186. }
  187. }
  188. }
  189. Dever::out('yes');
  190. }
  191. public function skuInput()
  192. {
  193. $id = Dever::input('search_option_info_id');
  194. $sku = Dever::db('goods/info_sku')->getData(array('info_id' => $id));
  195. $info = Dever::db('goods/info')->one($id);
  196. $info = Info::init(-1)->info($info, 'list_reorder');
  197. $html = '请先选择属性';
  198. if ($info['sell_attr']) {
  199. $head = '<thead><tr>';
  200. $body = '<tbody>';
  201. $option = array();
  202. foreach ($info['sell_attr'] as $k => $v) {
  203. $head .= '<th>'.$v['name'].'</th>';
  204. if (isset($v['option_sku'])) {
  205. $option[$k] = $v['option_sku'];
  206. }
  207. }
  208. $head .= '<th>原价</th>';
  209. $head .= '<th>现价</th>';
  210. $head .= '<th>库存</th>';
  211. $head .= '</tr></thead>';
  212. if ($option) {
  213. $option = Dever::cartesian($option);
  214. foreach ($option as $k => $v) {
  215. $body .= '<tr data-row="' .($k+1). '">';
  216. $key = $id = array();
  217. foreach ($v['name'] as $k1 => $v1) {
  218. $rows = 1;
  219. $body .= '<td width="50" rowspan="'.$rows.'">'.$v1.'</td>';
  220. $id[] = array
  221. (
  222. 'id' => $v['id'][$k1],
  223. 'attr_id' => $v['info_id'][$k1],
  224. );
  225. $key[] = $v['info_id'][$k1] . '-' . $v['id'][$k1];
  226. }
  227. $key = implode('_', $key);
  228. $s_price = $price = $num = '';
  229. if (isset($sku[$key])) {
  230. $s_price = $sku[$key]['s_price'];
  231. $price = $sku[$key]['price'];
  232. $num = $sku[$key]['num'];
  233. }
  234. $body .= '<td width="30"><input type="text" class="layui-input" name="s_price['.$k.']" value="'.$s_price.'"/></td>';
  235. $body .= '<td width="30"><input type="text" class="layui-input" name="price['.$k.']" value="'.$price.'"/></td>';
  236. $body .= '<td width="30"><input type="text" class="layui-input" name="num['.$k.']" value="'.$num.'"/><input type="hidden" name="key['.$k.']" value="'.$key.'"/><textarea style="display:none;" name="attr['.$k.']"/>'.json_encode($id).'</textarea></td>';
  237. $body .= '</tr>';
  238. }
  239. }
  240. $body .= '</tbody>';
  241. $html = $head . $body;
  242. }
  243. return $html;
  244. }
  245. }