Manage.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function sellOrderPs($id, $name, $data)
  7. {
  8. Dever::config('base')->hook = true;
  9. $order_id = Dever::param('order_id', $data);
  10. if ($order_id) {
  11. $info = Dever::db('shop/sell_order')->find(array('id' => $order_id));
  12. if ($info && $info['status'] < 3) {
  13. Dever::load('shop/lib/sell')->notice($info);
  14. }
  15. }
  16. }
  17. # 获取规格型号
  18. public function getSku($goods_id, $sku_id)
  19. {
  20. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($goods_id, $sku_id);
  21. if (isset($goods_info['sku'])) {
  22. $sku = $goods_info['sku']['string'];
  23. } else {
  24. $sku = '';
  25. }
  26. return $sku;
  27. }
  28. # 获取在途库存
  29. public function getGoodsTotal($type, $type_id, $goods_id, $sku_id)
  30. {
  31. $where['type'] = $type;
  32. $where['type_id'] = $type_id;
  33. $where['status'] = '2,3,4';
  34. $where['goods_id'] = $goods_id;
  35. $where['sku_id'] = $sku_id;
  36. $order = Dever::db('shop/buy_order_goods')->getGoodsTotal($where);
  37. if ($order && $order['total']) {
  38. return $order['total'];
  39. }
  40. return 0;
  41. }
  42. public function buyInfoRefundNum($id)
  43. {
  44. $where['status'] = 3;
  45. $where['order_id'] = $id;
  46. $order = Dever::db('shop/buy_order_goods')->getGoodsNum($where);
  47. if ($order && $order['total']) {
  48. return $order['total'];
  49. }
  50. return 0;
  51. }
  52. public function buyInfoRefundStatus($id, $table = 'buy_order')
  53. {
  54. $info = Dever::db('shop/' . $table)->find($id);
  55. if ($info['refund_cash'] > 0) {
  56. if ($info['status'] == 6 || $info['status'] == 8) {
  57. return '已退款';
  58. } else {
  59. return '有退款';
  60. }
  61. } elseif ($info['refund_status'] == 2) {
  62. return '已申请';
  63. } else {
  64. return '未申请';
  65. }
  66. }
  67. public function shopInfoType($type)
  68. {
  69. $config_type = Dever::db('shop/info')->config['config_type'];
  70. return $config_type[$type];
  71. }
  72. public function getTotalCash($id)
  73. {
  74. $order = Dever::db('shop/sell_order')->one($id);
  75. $cash = 0;
  76. $cash = $order['oprice'];
  77. return $cash;
  78. }
  79. public function getOrderUrl($order_id, $order_num, $search)
  80. {
  81. $url = Dever::load('manage/database')->url('list', $order_id, 'buy_order_goods&project=shop&order_id='.$order_id.'&page_type=1');
  82. if ($search == 3) {
  83. $url .= '&type=2&search_option_type=2';
  84. } elseif ($search == 2) {
  85. $url .= '&type=1&search_option_type=3';
  86. } else {
  87. $url .= '&type=1&search_option_type=1';
  88. }
  89. $url = '<a href="'.$url.'">'.$order_num.'</a>';
  90. return $url;
  91. }
  92. public function showCash($cash, $p_cash = 0)
  93. {
  94. if (!$cash) {
  95. $cash = 0;
  96. }
  97. if (!$p_cash) {
  98. $p_cash = 0;
  99. }
  100. return $cash - $p_cash;
  101. }
  102. # 获取用户信息
  103. public function user($id, $type = 1)
  104. {
  105. $info = Dever::db('shop/sell_order')->one($id);
  106. if ($info['uid'] && $info['uid'] > 0) {
  107. $user = Dever::db('passport/user')->one($info['uid']);
  108. $result = $user['username'];
  109. if ($type == 1 && $info['mobile']) {
  110. $result .= '('.$info['mobile'].')';
  111. }
  112. } else {
  113. $result = $info['mobile'];
  114. }
  115. return $result;
  116. }
  117. # 获取订单信息
  118. public function sell_order($id)
  119. {
  120. $table = array();
  121. $info = Dever::db('shop/sell_order')->one($id);
  122. $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
  123. foreach ($goods as $k => $v) {
  124. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
  125. //print_r($goods_info);die;
  126. $table[$goods_info['name']] = $v['price'];
  127. }
  128. return Dever::table($table);
  129. }
  130. /**
  131. * 更新信息
  132. *
  133. * @return mixed
  134. */
  135. public function upInfo($id, $name, $data)
  136. {
  137. Dever::config('base')->hook = true;
  138. }
  139. /**
  140. * 更新信息
  141. *
  142. * @return mixed
  143. */
  144. public function printInsert($id, $name, $data)
  145. {
  146. Dever::config('base')->hook = true;
  147. $name = Dever::param('name', $data);
  148. $number = Dever::param('number', $data);
  149. $phonenum = Dever::param('phonenum', $data);
  150. $key = Dever::param('key', $data);
  151. if ($number && $key) {
  152. $data = array();
  153. $data['name'] = $name;
  154. $data['number'] = $number;
  155. $data['phonenum'] = $phonenum;
  156. $data['key'] = $key;
  157. $result = Dever::load('mshop/lib/feieyun')->add(array($data));
  158. if (isset($result['no'][0]) && $result['no'][0] && strstr($result['no'][0], '编号不合法')) {
  159. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 10));
  160. } else {
  161. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 1));
  162. }
  163. }
  164. }
  165. /**
  166. * 更新信息
  167. *
  168. * @return mixed
  169. */
  170. public function printUpdate($id, $name, $data)
  171. {
  172. Dever::config('base')->hook = true;
  173. $info = Dever::db('shop/print')->one($id);
  174. $name = Dever::param('name', $data);
  175. $phonenum = Dever::param('phonenum', $data);
  176. if ($info && $name) {
  177. if ($info['status'] == 10) {
  178. $this->printInsert($id, $name, $info);
  179. } else {
  180. Dever::load('mshop/lib/feieyun')->edit($info['number'], $name, $phonenum);
  181. }
  182. }
  183. }
  184. /**
  185. * 打印机状态
  186. *
  187. * @return mixed
  188. */
  189. public function printStatus($status, $sn)
  190. {
  191. return $status >= 10 ? '绑定失败' : Dever::load('mshop/lib/feieyun')->status($sn);
  192. }
  193. public function buyOrderUpdate($id, $name, $data)
  194. {
  195. Dever::config('base')->hook = true;
  196. $update = array();
  197. $audit = Dever::param('audit', $data);
  198. $info = Dever::db('shop/buy_order')->one($id);
  199. if ($audit > 1 && $info && $info['status'] == 2) {
  200. if ($audit == 2) {
  201. # 成功
  202. Dever::setInput('order_id', $id);
  203. Dever::load('mshop/lib/buy.audit_commit');
  204. } else {
  205. # 退款
  206. $shop = Dever::db('shop/info')->find($info['type_id']);
  207. Dever::load('shop/lib/refund')->set('buy')->apply(1, $shop['id'], $id, false, 3, 0, '未通过审核');
  208. }
  209. }
  210. }
  211. public function sellOrderUpdate($id, $name, $data)
  212. {
  213. Dever::config('base')->hook = true;
  214. $update = array();
  215. $audit = Dever::param('audit', $data);
  216. $info = Dever::db('shop/sell_order')->one($id);
  217. if ($audit > 1 && $info && $info['status'] == 2) {
  218. if ($audit == 2) {
  219. # 成功
  220. Dever::setInput('order_id', $id);
  221. Dever::load('shop/lib/sell.audit_commit');
  222. } else {
  223. # 退款
  224. $shop = Dever::db('shop/info')->find($info['shop_id']);
  225. Dever::load('shop/lib/refund')->set('sell')->apply(1, $shop['id'], $id, false, 3, 0, '未通过审核');
  226. }
  227. }
  228. }
  229. /**
  230. * 更新信息
  231. *
  232. * @return mixed
  233. */
  234. public function couponUpdate($id, $name, $data)
  235. {
  236. Dever::config('base')->hook = true;
  237. $update = array();
  238. $coupon = Dever::param('coupon', $data);
  239. if ($coupon) {
  240. $temp = is_string($coupon) ? explode(',', $coupon) : $coupon;
  241. $update['method'] = $temp[0];
  242. $update['coupon_id'] = $temp[1];
  243. }
  244. $shop_id = Dever::param('shop_id', $data);
  245. if ($shop_id) {
  246. $shop = Dever::db('shop/info')->find($shop_id);
  247. $update['city'] = $shop['city'];
  248. }
  249. if (isset($update) && $update) {
  250. $update['where_id'] = $id;
  251. Dever::db('shop/coupon')->update($update);
  252. }
  253. }
  254. /**
  255. * 更新信息
  256. *
  257. * @return mixed
  258. */
  259. public function infoUpdate($id, $name, $data)
  260. {
  261. $update = array();
  262. $area = Dever::param('area', $data);
  263. if ($area) {
  264. $temp = is_string($area) ? explode(',', $area) : $area;
  265. $update['province'] = $temp[0];
  266. $update['city'] = $temp[1];
  267. if (isset($temp[2])) {
  268. $update['county'] = $temp[2];
  269. }
  270. if (isset($temp[3])) {
  271. $update['town'] = $temp[3];
  272. }
  273. if (is_array($area)) {
  274. $area = implode(',', $area);
  275. }
  276. $gup['option_shop_id'] = $id;
  277. $gup['set_area'] = $area;
  278. Dever::db('shop/goods_sku')->updates($gup);
  279. Dever::db('shop/sell_order')->updates($gup);
  280. unset($gup['option_shop_id']);
  281. $gup['option_type_id'] = $id;
  282. $gup['option_type'] = 1;
  283. Dever::db('shop/buy_order')->updates($gup);
  284. Dever::db('shop/out_order')->updates($gup);
  285. }
  286. $map = Dever::param('map', $data);
  287. if ($map) {
  288. $temp = is_string($map) ? explode(',', $map) : $map;
  289. if (isset($temp[1])) {
  290. $update['lng'] = $temp[1];
  291. $update['lat'] = $temp[2];
  292. $address = Dever::param('address', $data);
  293. $update['coord_address'] = Dever::load('shop/lib/info')->address($temp[1], $temp[2]);
  294. if (!$address && $update['coord_address']) {
  295. $update['address'] = $update['coord_address'];
  296. }
  297. }
  298. }
  299. $act = Dever::param('act', $data);
  300. if ($act) {
  301. foreach ($act as $k => $v) {
  302. $w = array();
  303. $w['shop_id'] = $id;
  304. $w['act_id'] = $k;
  305. foreach ($v as $k1 => $v1) {
  306. $w['shop_coupon_id'] = $v1;
  307. $info = Dever::db('shop/coupon_act')->find($w);
  308. if (!$info) {
  309. Dever::db('shop/coupon_act')->insert($w);
  310. }
  311. }
  312. }
  313. }
  314. //Dever::upLinkage($update, $id, $data, 'goods', 'shop/goods', 'shop_id', 'goods_id', 'category_id');
  315. //Dever::upLinkage($update, $id, $data, 'factory', 'shop/factory', 'shop_id', 'factory_id', 'city');
  316. //Dever::upLinkage($update, $id, $data, 'store', 'shop/store', 'shop_id', 'store_id', 'city');
  317. if (isset($update) && $update) {
  318. $update['where_id'] = $id;
  319. Dever::db('shop/info')->update($update);
  320. }
  321. $truename = Dever::param('truename', $data);
  322. $mobile = Dever::param('mobile', $data);
  323. if ($mobile) {
  324. $member = Dever::db('shop/member')->one(array('shop_id' => $id, 'mobile' => $mobile));
  325. $update = array();
  326. $update['shop_id'] = $id;
  327. $update['name'] = $truename;
  328. $update['mobile'] = $mobile;
  329. if ($member) {
  330. $update['where_id'] = $member['id'];
  331. Dever::db('shop/member')->update($update);
  332. } else {
  333. Dever::db('shop/member')->insert($update);
  334. }
  335. }
  336. }
  337. private function updateParam()
  338. {
  339. }
  340. /**
  341. * 更新商品信息
  342. *
  343. * @return mixed
  344. */
  345. public function goodsUpdate($id, $name, $data)
  346. {
  347. $update = array();
  348. $state = Dever::param('state', $data);
  349. if ($state) {
  350. Dever::config('base')->after = true;
  351. $info = Dever::db('shop/goods')->one($id);
  352. $shop_id = $info['shop_id'];
  353. $shop = Dever::db('shop/info')->one($shop_id);
  354. if ($shop && $shop['goods']) {
  355. $goods = Dever::json_decode($shop['goods']);
  356. if (isset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']])) {
  357. if ($state == 2) {
  358. unset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']]);
  359. }
  360. if (count($goods['level_' . $info['category_id']]['value']) <= 0) {
  361. unset($goods['level_' . $info['category_id']]);
  362. }
  363. } elseif ($state == 1) {
  364. $goods_info = Dever::db('goods/info')->one($info['goods_id']);
  365. $cate = Dever::load('category/api')->string($info['category_id']);
  366. $goods['level_' . $info['category_id']]['id'] = $info['category_id'];
  367. $goods['level_' . $info['category_id']]['name'] = $cate;
  368. $goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']] = array
  369. (
  370. 'id' => $info['goods_id'],
  371. 'name' => $goods_info['name'],
  372. 'state' => 1,
  373. );
  374. }
  375. $set['goods'] = Dever::json_encode($goods);
  376. $set['where_id'] = $shop_id;
  377. Dever::db('shop/info')->update($set);
  378. }
  379. }
  380. }
  381. /**
  382. * 更新库存信息
  383. *
  384. * @return mixed
  385. */
  386. public function skuUpdate($id, $name, $data)
  387. {
  388. $update = array();
  389. $add_num = Dever::param('add_num', $data);
  390. if ($add_num) {
  391. $state = Dever::db('shop/goods_sku')->updateTotal(array('where_id' => $id, 'total_num' => $add_num));
  392. if ($state) {
  393. $state = Dever::db('shop/goods_sku')->update(array('where_id' => $id, 'add_num' => 0));
  394. $info = Dever::db('shop/goods_sku')->one($id);
  395. $goods = Dever::db('shop/goods')->one(array('goods_id' => $info['goods_id'], 'shop_id' => $info['shop_id']));
  396. if ($goods) {
  397. Dever::db('shop/goods')->update(array('where_id' => $goods['id'], 'total_num' => $info['total_num'], 'add_num' => 0));
  398. }
  399. if ($add_num < 0) {
  400. # 记录出库日志
  401. } else {
  402. # 记录入库日志
  403. }
  404. }
  405. }
  406. }
  407. # 获取供货商信息
  408. public function buyInfo($type = '', $type_id = '')
  409. {
  410. if ($type == 1) {
  411. $type_info = Dever::db('shop/info')->one($type_id);
  412. return $type_info['name'] . '('.$type_info['mobile'].')';
  413. } elseif ($type == 2) {
  414. $type_info = Dever::db('store/info')->one($type_id);
  415. $sign = Dever::login($type_id);
  416. $link = Dever::url('home?sign=' . $sign, 'store');
  417. //return $type_info['name'] . '('.$type_info['mobile'].')<br /><a href="'.$link.'" target="_blank">进入仓库管理</a>';
  418. return $type_info['name'] . '('.$type_info['mobile'].')';
  419. } elseif ($type == 3) {
  420. $sign = Dever::login($type_id);
  421. $link = Dever::url('home?sign=' . $sign, 'factory');
  422. $type_info = Dever::db('factory/info')->one($type_id);
  423. //return $type_info['name'] . '('.$type_info['mobile'].')<br /><a href="'.$link.'" target="_blank">进入工厂管理</a>';
  424. return $type_info['name'] . '('.$type_info['mobile'].')';
  425. } else {
  426. return '无';
  427. }
  428. }
  429. /**
  430. * 更新信息
  431. *
  432. * @return mixed
  433. */
  434. public function buyOrderPs($id, $name, $data)
  435. {
  436. $order_id = Dever::param('order_id', $data);
  437. if ($order_id) {
  438. $update['where_id'] = $order_id;
  439. $update['set_status'] = 4;
  440. Dever::db('shop/buy_order')->update($update);
  441. }
  442. }
  443. # 获取门店
  444. public function search_api()
  445. {
  446. return Dever::search('shop/info');
  447. }
  448. # 获取环比增长
  449. public function getGoodsHb($num, $day, $goods_id)
  450. {
  451. $where = array('day' => $day, 'goods_id' => $goods_id);
  452. $search = Dever::search_button();
  453. if ($search) {
  454. $where['config']['group'] = $search[0];
  455. $where['config']['col'] = str_replace('|id', '', $search[1]);
  456. }
  457. if ($num < 0) {
  458. $num = 0;
  459. }
  460. $prev = Dever::db('shop/goods_stat')->prev($where);
  461. if ($prev && $num > 0 && $prev['num'] >= 0) {
  462. $n = $prev['num'];
  463. if ($n == 0) {
  464. $n = 1;
  465. }
  466. $hb = round(($num-$prev['num'])/$n, 2)*100;
  467. } else {
  468. $hb = 0;
  469. }
  470. return $hb . '%';
  471. }
  472. public function getUserHb($num, $total, $day)
  473. {
  474. $result = $this->getUserStat($num, $total, 0);
  475. $where = array('day' => $day);
  476. $search = Dever::search_button();
  477. if ($search) {
  478. $where['config']['group'] = $search[0];
  479. $where['config']['col'] = str_replace('|id', '', $search[1]);
  480. }
  481. $hb = 0;
  482. $prev = Dever::db('shop/user_stat')->prev($where);
  483. if ($prev) {
  484. $prev = $this->getUserStat($prev['num'], $prev['total'], $prev['order_num']);
  485. if ($result['fg'] > 0 && $prev['fg'] >= 0) {
  486. $fg = $prev['fg'];
  487. if ($fg == 0) {
  488. $fg = 1;
  489. }
  490. $hb = round(($result['fg']-$prev['fg'])/$fg, 2)*100;
  491. }
  492. }
  493. return $hb . '%';
  494. }
  495. public function getUserStat($num, $total, $order_num)
  496. {
  497. //print_r($info);die;
  498. if ($num && $total) {
  499. $result['fg'] = round($num/$total, 2);
  500. } else {
  501. $result['fg'] = 0;
  502. }
  503. if ($order_num) {
  504. $result['per_num'] = round($order_num/$total, 2);
  505. } else {
  506. $result['per_num'] = 0;
  507. }
  508. return $result;
  509. }
  510. # 获取环比增长
  511. public function getUserRankHb($num, $day)
  512. {
  513. $where = array('day' => $day);
  514. $search = Dever::search_button();
  515. if ($search) {
  516. $where['config']['group'] = $search[0];
  517. $where['config']['col'] = str_replace('|id', '', $search[1]);
  518. }
  519. if ($num < 0) {
  520. $num = 0;
  521. }
  522. $prev = Dever::db('shop/user_rank_stat')->prev($where);
  523. if ($prev && $num > 0 && $prev['num'] >= 0) {
  524. $n = $prev['num'];
  525. if ($n == 0) {
  526. $n = 1;
  527. }
  528. $hb = round(($num-$prev['num'])/$n, 2)*100;
  529. } else {
  530. $hb = 0;
  531. }
  532. return $hb . '%';
  533. }
  534. # 确认收货
  535. public function setSellOrderStatus_api()
  536. {
  537. $order_id = Dever::input('order_id');
  538. $info = Dever::db('shop/sell_order')->find($order_id);
  539. if ($info) {
  540. Dever::load('shop/lib/sell')->finish($info, $info['shop_id']);
  541. return 'reload';
  542. } else {
  543. Dever::alert('错误的订单号');
  544. }
  545. }
  546. public function searchName($where)
  547. {
  548. $data = Dever::db('store/info')->like($where);
  549. if (!$data) {
  550. $data = Dever::db('shop/info')->like($where);
  551. }
  552. return $data;
  553. }
  554. public function searchFName($where)
  555. {
  556. $data = Dever::db('store/info')->like($where);
  557. if (!$data) {
  558. $data = Dever::db('factory/info')->like($where);
  559. }
  560. return $data;
  561. }
  562. }