Manage.php 9.5 KB

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