Manage.php 11 KB

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