Manage.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <?php
  2. namespace Goods\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function getByName_api()
  7. {
  8. $data = Dever::db('goods/info')->getAllByName(array
  9. (
  10. 'name' => Dever::input('term'))
  11. );
  12. if ($data) {
  13. return $data;
  14. }
  15. return array
  16. (
  17. 0 => array('id' => -1, 'value' => '没有找到您搜索的数据', 'label' => '没有找到您搜索的数据'),
  18. );
  19. }
  20. public function getByCate()
  21. {
  22. $cate = Dever::input('cate');
  23. $data = Dever::db('goods/info')->getAllByCate(array('top_category_id' => $cate));
  24. return Dever::load('manage/database')->getAjax($data);
  25. }
  26. public function search_api()
  27. {
  28. $where = array();
  29. $cate = Dever::input('cate');
  30. if ($cate) {
  31. $where['cate_id'] = $cate;
  32. }
  33. $price_type = Dever::input('price_type');
  34. if ($price_type) {
  35. $where['price_type'] = $price_type;
  36. }
  37. return Dever::search('goods/info', $where);
  38. }
  39. public function search_sku_api()
  40. {
  41. $where = array();
  42. $info_id = Dever::input('info_id');
  43. if ($info_id) {
  44. $where['info_id'] = $info_id;
  45. }
  46. $data = Dever::search('goods/info_sku', $where);
  47. if ($data) {
  48. foreach ($data as $k => $v) {
  49. $v['attr'] = Dever::json_decode($v['attr']);
  50. if ($v['attr']) {
  51. $v['attr'] = Dever::load('attr/api')->getInfoByJson($v['attr']);
  52. $v['name'] = $v['attr']['string'];
  53. }
  54. }
  55. }
  56. return $data;
  57. }
  58. /**
  59. * 更新信息
  60. *
  61. * @return mixed
  62. */
  63. public function infoUpdate($id, $name, $data)
  64. {
  65. $status = Dever::param('status', $data);
  66. if ($status > 0) {
  67. Dever::db('shop/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
  68. Dever::db('store/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
  69. Dever::db('factory/goods')->updates(array('option_goods_id' => $id, 'set_status' => $status));
  70. }
  71. # 更新分类id
  72. $category = Dever::param('category', $data);
  73. if ($category) {
  74. if (is_array($category)) {
  75. $category_id = end($category);
  76. $top_category_id = $category[0];
  77. if (isset($category[1])) {
  78. $second_category_id = $category[1];
  79. } else {
  80. $second_category_id = $category[0];
  81. }
  82. } else {
  83. $category_id = $category;
  84. $top_category_id = $category;
  85. $second_category_id = $category;
  86. }
  87. $update['top_category_id'] = $top_category_id;
  88. $update['second_category_id'] = $second_category_id;
  89. $update['category_id'] = $category_id;
  90. }
  91. $pic = Dever::param('pic', $data);
  92. $pic_cover = Dever::param('pic_cover', $data);
  93. if ($pic && !$pic_cover) {
  94. if (is_string($pic)) {
  95. $pic = explode(',', $pic);
  96. }
  97. $update['pic_cover'] = $pic[0];
  98. }
  99. if (isset($update)) {
  100. $update['where_id'] = $id;
  101. Dever::db('goods/info')->update($update);
  102. }
  103. }
  104. /**
  105. * 更新需求属性信息
  106. *
  107. * @return mixed
  108. */
  109. public function attrUpdate($id, $name, $data)
  110. {
  111. print_r($data);die;
  112. foreach ($data as $k => $v) {
  113. }
  114. }
  115. public function column($cate, $im = ',')
  116. {
  117. if ($cate) {
  118. $cate = explode(',', $cate);
  119. $result = array();
  120. foreach ($cate as $k => $v) {
  121. $info = Dever::db('goods/column')->one($v);
  122. $result[$k] = $info['name'];
  123. }
  124. $result = implode($im, $result);
  125. return $result;
  126. }
  127. return '';
  128. }
  129. /**
  130. * 显示信息
  131. *
  132. * @return mixed
  133. */
  134. public function info($id)
  135. {
  136. $info = Dever::db('goods/info')->one($id);
  137. if ($info) {
  138. $table['编号'] = $info['id'];
  139. $table['栏目'] = $this->column($info['column_id']);
  140. //$table['标题'] = $info['name'];
  141. $table['分类'] = Dever::load("category/api.string", $info['category']);
  142. if ($info['cover']) {
  143. $table['商品图'] = '<img src="'.$info['cover'].'" width="150" />';
  144. }
  145. if ($info['price_type'] == 3) {
  146. # 获取套餐的商品
  147. $goods = Dever::array_decode($info['goods']);
  148. foreach ($goods as $k => $v) {
  149. $goods_info = Dever::db('goods/info')->one($v['goods_id']);
  150. if ($goods_info) {
  151. $table['套餐商品'][] = $v['num'] . '个' . $goods_info['name'];
  152. }
  153. }
  154. $table['套餐商品'] = implode(',', $table['套餐商品']);
  155. } elseif ($info['price_type'] == 4) {
  156. # 获取套餐的商品
  157. $goods = Dever::array_decode($info['goods']);
  158. foreach ($goods as $k => $v) {
  159. $goods_info = Dever::db('goods/info')->one($v['goods_id']);
  160. if ($goods_info) {
  161. $table['组合商品'][] = $v['num'] . '个' . $goods_info['name'];
  162. }
  163. }
  164. $table['组合商品'] = implode(',', $table['组合商品']);
  165. }
  166. $attr = $this->attrInfo($info);
  167. if ($attr) {
  168. $table['属性'] = $attr;
  169. }
  170. $table['价格'] = Dever::load('goods/lib/sku')->table($info['id'], false, false, false, false);
  171. if ($info['udate']) {
  172. $table['更新时间'] = date("Y-m-d H:i:s", $info['udate']);
  173. }
  174. if ($info['cdate']) {
  175. $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']);
  176. }
  177. }
  178. return Dever::table($table);
  179. }
  180. private function attrInfo($info)
  181. {
  182. $table = array();
  183. $class = Info::init($info['top_category_id']);
  184. if ($info) {
  185. $info = $class->info($info);
  186. if ($info && isset($info['attr'])) {
  187. foreach ($info['attr'] as $k => $v) {
  188. if ($v['value_string']) {
  189. $table[$v['name']] = $v['value_string'];
  190. }
  191. }
  192. }
  193. }
  194. return $table ? Dever::table($table) : false;
  195. }
  196. public function area($id, $name, $data)
  197. {
  198. # 不再执行syncone等后续操作
  199. Dever::config('base')->after = 1;
  200. $type = Dever::input('type');
  201. $area = Dever::param('area', $data);
  202. if ($area) {
  203. if (isset($area[2])) {
  204. $update['district_id'] = $area[2];
  205. }
  206. if (isset($area[1])) {
  207. $update['city_id'] = $area[1];
  208. }
  209. if (isset($area[0])) {
  210. $update['province_id'] = $area[0];
  211. }
  212. if (isset($update)) {
  213. $update['where_id'] = $id;
  214. Dever::db($type . '/info')->update($update);
  215. }
  216. }
  217. }
  218. /**
  219. * 显示用户信息
  220. *
  221. * @return mixed
  222. */
  223. public function showUserInfo($id)
  224. {
  225. $info = Dever::db('goods/card_code')->find($id);
  226. $table = array();
  227. if ($info && $info['status'] > 1 && $info['uid'] && $info['uid'] > 0) {
  228. $user = Dever::load('passport/user-one', $info['uid']);
  229. $shop = Dever::load('shop/info-one', $info['shop_id']);
  230. if ($user) {
  231. $table['领取门店'] = $shop['name'] . '('.$shop['mobile'].')';
  232. $table['领取人'] = $user['username'] . '('.$info['uid'].')';
  233. $table['手机号'] = $user['mobile'];
  234. $table['兑换时间'] = date('Y-m-d H:i:s', $info['ddate']);
  235. }
  236. }
  237. return Dever::table($table);
  238. }
  239. /**
  240. * 创建兑换码
  241. *
  242. * @return mixed
  243. */
  244. public function createCard($id, $name, $param)
  245. {
  246. $num = Dever::param('num', $param);
  247. $card_id = Dever::param('card_id', $param);
  248. $info = Dever::db('goods/card')->find($card_id);
  249. if ($info && $num > 0) {
  250. for ($i = 0; $i< $num;$i++) {
  251. $this->createCode($info);
  252. }
  253. }
  254. }
  255. private function createCode($info)
  256. {
  257. # 生成卡号和密码
  258. $card = $info['card_prefix'] . Dever::rand($info['card_len'], $info['card_type'] - 1);
  259. $pwd = $info['pwd_prefix'] . Dever::rand($info['pwd_len'], $info['pwd_type'] - 1);
  260. $where['card'] = $card;
  261. $where['pwd'] = $pwd;
  262. $state = Dever::db('goods/card_code')->find($where);
  263. if (!$state) {
  264. $where['card_id'] = $info['id'];
  265. if ($info['type'] == 1) {
  266. $info['day'] = 3650;
  267. }
  268. $where['edate'] = time() + ($info['day']*86400);
  269. Dever::db('goods/card_code')->insert($where);
  270. } else {
  271. $this->createCode($info);
  272. }
  273. }
  274. /**
  275. * 作废
  276. *
  277. * @return mixed
  278. */
  279. public function drop_api($id)
  280. {
  281. $update['where_id'] = $id;
  282. $update['type'] = 4;
  283. Dever::db('goods/card_code')->update($update);
  284. return 'ok';
  285. }
  286. public function recovery_api($id)
  287. {
  288. $update['where_id'] = $id;
  289. $update['type'] = 1;
  290. Dever::db('goods/card_code')->update($update);
  291. return 'ok';
  292. }
  293. public function editor_api()
  294. {
  295. $data['name'] = '商品';
  296. $where = array();
  297. $name = Dever::input('search_name');
  298. $cate = Dever::input('search_cate');
  299. if ($name) {
  300. $where['name'] = $name;
  301. }
  302. if ($cate > 0) {
  303. $where['column_id'] = $cate;
  304. }
  305. $data['file'] = Dever::db('goods/info')->getPageAll($where);
  306. $data['cate'] = Dever::db('goods/column')->select();
  307. if ($data['file']) {
  308. foreach ($data['file'] as $k => $v) {
  309. $data['file'][$k]['source_name'] = $v['name'];
  310. $data['file'][$k]['file'] = $v['cover'];
  311. $data['file'][$k]['pic'] = $v['cover'];
  312. }
  313. }
  314. return $data;
  315. }
  316. }