Manage.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. # 金额确认
  7. public function sign($id, $name, $data)
  8. {
  9. $cash = Dever::param('cash', $data);
  10. $sign = Dever::db('shop/sign')->find($id);
  11. if ($cash && $cash > 0) {
  12. Dever::load('shop/lib/sign')->account_check($sign, $cash);
  13. }
  14. $create_shop = Dever::param('create_shop', $data);
  15. $shop_id = Dever::param('shop_id', $data);
  16. if ($create_shop) {
  17. if ($create_shop == 1) {
  18. # 绑定门店
  19. if (!$shop_id) {
  20. Dever::alert('请选择门店');
  21. }
  22. Dever::load('shop/lib/sign')->bind($id, $shop_id);
  23. } elseif ($create_shop == 2) {
  24. # 生成门店
  25. //Dever::alert('暂时无法生成门店');
  26. $shop_id = $this->createShop($sign);
  27. if ($shop_id) {
  28. Dever::load('shop/lib/sign')->bind($id, $shop_id);
  29. }
  30. }
  31. }
  32. }
  33. private function createShop($info)
  34. {
  35. $data['name'] = $info['shop_name'];
  36. $data['truename'] = $info['name'];
  37. $data['mobile'] = $info['mobile'];
  38. $data['type'] = 1;
  39. $state = Dever::db('shop/info')->find($data);
  40. if ($state) {
  41. if (!$state['mid']) {
  42. return $state['id'];
  43. } else {
  44. return false;
  45. }
  46. } else {
  47. $data['area'] = $info['shop_area'];
  48. $data['address'] = $info['shop_address'];
  49. $data['license'] = $info['license'];
  50. $data['license_number'] = $info['license_number'];
  51. $data['company_name'] = $info['company_name'];
  52. $data['idcard_front'] = $info['idcard_front'];
  53. $data['idcard_back'] = $info['idcard_back'];
  54. $data['license'] = $info['license'];
  55. return Dever::db('shop/info')->insert($data);
  56. }
  57. }
  58. public function sellOrderPs($id, $name, $data)
  59. {
  60. Dever::config('base')->hook = true;
  61. $order_id = Dever::param('order_id', $data);
  62. if ($order_id) {
  63. $info = Dever::db('shop/sell_order')->find(array('id' => $order_id));
  64. if ($info && $info['status'] < 3) {
  65. Dever::load('shop/lib/sell')->notice($info);
  66. }
  67. }
  68. }
  69. # 获取规格型号
  70. public function getSku($goods_id, $sku_id)
  71. {
  72. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($goods_id, $sku_id);
  73. if (isset($goods_info['sku'])) {
  74. $sku = $goods_info['sku']['string'];
  75. } else {
  76. $sku = '';
  77. }
  78. return $sku;
  79. }
  80. # 获取在途库存
  81. public function getGoodsTotal($type, $type_id, $goods_id, $sku_id)
  82. {
  83. $where['type'] = $type;
  84. $where['type_id'] = $type_id;
  85. $where['status'] = '2,3,4';
  86. $where['goods_id'] = $goods_id;
  87. $where['sku_id'] = $sku_id;
  88. $order = Dever::db('shop/buy_order_goods')->getGoodsTotal($where);
  89. if ($order && $order['total']) {
  90. return $order['total'];
  91. }
  92. return 0;
  93. }
  94. public function buyInfoRefundNum($id)
  95. {
  96. $where['status'] = 3;
  97. $where['order_id'] = $id;
  98. $order = Dever::db('shop/buy_order_goods')->getGoodsNum($where);
  99. if ($order && $order['total']) {
  100. return $order['total'];
  101. }
  102. return 0;
  103. }
  104. public function buyInfoRefundStatus($id, $table = 'buy_order')
  105. {
  106. $info = Dever::db('shop/' . $table)->find($id);
  107. if ($info['refund_cash'] > 0) {
  108. if ($info['status'] == 6 || $info['status'] == 8) {
  109. return '已退款';
  110. } else {
  111. return '有退款';
  112. }
  113. } elseif ($info['refund_status'] == 2) {
  114. return '已申请';
  115. } else {
  116. return '未申请';
  117. }
  118. }
  119. public function shopInfoType($type)
  120. {
  121. $config_type = Dever::db('shop/info')->config['config_type'];
  122. return $config_type[$type];
  123. }
  124. public function getTotalCash($id)
  125. {
  126. $order = Dever::db('shop/sell_order')->one($id);
  127. $cash = 0;
  128. $cash = $order['oprice'];
  129. return round($cash, 2);
  130. }
  131. public function getOrderUrl($source_type, $order_id, $order_num, $search)
  132. {
  133. //$url = Dever::load('manage/database')->url('list', $order_id, 'buy_order_goods&project=shop&order_id='.$order_id.'&page_type=1');
  134. if ($source_type == 4) {
  135. $url = Dever::url('project/database/list&project=shop&search_option_shop_type=1&page_type=2&menu_id=85&table=sell_order_goods&project=shop&order_id='.$order_id.'&page_type=&search_option_shop_type=1&menu=shop&menu_id=85&search_option_state=1&menu_id=85', 'manage');
  136. } else {
  137. $url = Dever::url('project/database/list?project=cash&search_option_search=1&search_option_type=1&page_type=2&table=buy_order_goods&project=shop&order_id='.$order_id.'&page_type=1&menu=cash&menu_id=124&search_option_state=1', 'manage');
  138. if ($search == 3) {
  139. $url .= '&type=2&search_option_type=2';
  140. } elseif ($search == 2) {
  141. $url .= '&type=1&search_option_type=3';
  142. } else {
  143. $url .= '&type=1&search_option_type=1';
  144. }
  145. }
  146. $url = '<a href="'.$url.'">'.$order_num.'</a>';
  147. return $url;
  148. }
  149. public function showCash($cash, $p_cash = 0)
  150. {
  151. if (!$cash) {
  152. $cash = 0;
  153. }
  154. if (!$p_cash) {
  155. $p_cash = 0;
  156. }
  157. return round($cash - $p_cash,2);
  158. }
  159. # 获取用户信息
  160. public function user($id, $type = 1)
  161. {
  162. $info = Dever::db('shop/sell_order')->one($id);
  163. if ($info['uid'] && $info['uid'] > 0) {
  164. $user = Dever::db('passport/user')->one($info['uid']);
  165. $result = $user['username'];
  166. if ($type == 1 && $info['mobile']) {
  167. $result .= '('.$info['mobile'].')';
  168. }
  169. } else {
  170. $result = $info['mobile'];
  171. }
  172. return $result;
  173. }
  174. # 获取订单信息
  175. public function sell_order($id)
  176. {
  177. $table = array();
  178. $info = Dever::db('shop/sell_order')->one($id);
  179. $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
  180. foreach ($goods as $k => $v) {
  181. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
  182. //print_r($goods_info);die;
  183. $table[$goods_info['name']] = $v['price'];
  184. }
  185. return Dever::table($table);
  186. }
  187. /**
  188. * 更新信息
  189. *
  190. * @return mixed
  191. */
  192. public function upInfo($id, $name, $data)
  193. {
  194. Dever::config('base')->hook = true;
  195. }
  196. /**
  197. * 更新信息
  198. *
  199. * @return mixed
  200. */
  201. public function printInsert($id, $name, $data)
  202. {
  203. Dever::config('base')->hook = true;
  204. $name = Dever::param('name', $data);
  205. $number = Dever::param('number', $data);
  206. $phonenum = Dever::param('phonenum', $data);
  207. $key = Dever::param('key', $data);
  208. if ($number && $key) {
  209. $data = array();
  210. $data['name'] = $name;
  211. $data['number'] = $number;
  212. $data['phonenum'] = $phonenum;
  213. $data['key'] = $key;
  214. $result = Dever::load('mshop/lib/feieyun')->add(array($data));
  215. if (isset($result['no'][0]) && $result['no'][0] && strstr($result['no'][0], '编号不合法')) {
  216. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 10));
  217. } else {
  218. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 1));
  219. }
  220. }
  221. }
  222. /**
  223. * 更新信息
  224. *
  225. * @return mixed
  226. */
  227. public function printUpdate($id, $name, $data)
  228. {
  229. Dever::config('base')->hook = true;
  230. $info = Dever::db('shop/print')->one($id);
  231. $name = Dever::param('name', $data);
  232. $phonenum = Dever::param('phonenum', $data);
  233. if ($info && $name) {
  234. if ($info['status'] == 10) {
  235. $this->printInsert($id, $name, $info);
  236. } else {
  237. Dever::load('mshop/lib/feieyun')->edit($info['number'], $name, $phonenum);
  238. }
  239. }
  240. }
  241. /**
  242. * 打印机状态
  243. *
  244. * @return mixed
  245. */
  246. public function printStatus($status, $sn)
  247. {
  248. return $status >= 10 ? '绑定失败' : Dever::load('mshop/lib/feieyun')->status($sn);
  249. }
  250. public function buyOrderUpdate($id, $name, $data)
  251. {
  252. Dever::config('base')->hook = true;
  253. $update = array();
  254. $audit = Dever::param('audit', $data);
  255. $info = Dever::db('shop/buy_order')->one($id);
  256. if ($audit > 1 && $info && $info['status'] == 2) {
  257. if ($audit == 2) {
  258. # 成功
  259. Dever::setInput('order_id', $id);
  260. Dever::load('mshop/lib/buy.audit_commit');
  261. } else {
  262. # 退款
  263. $shop = Dever::db('shop/info')->find($info['type_id']);
  264. Dever::load('shop/lib/refund')->set('buy')->apply(1, $shop['id'], $id, false, 3, 0, '未通过审核');
  265. }
  266. }
  267. }
  268. public function sellOrderUpdate($id, $name, $data)
  269. {
  270. Dever::config('base')->hook = true;
  271. $update = array();
  272. $audit = Dever::param('audit', $data);
  273. $info = Dever::db('shop/sell_order')->one($id);
  274. if ($audit > 1 && $info && $info['status'] == 2) {
  275. if ($audit == 2) {
  276. # 成功
  277. Dever::setInput('order_id', $id);
  278. Dever::load('shop/lib/sell.audit_commit');
  279. } else {
  280. # 退款
  281. $shop = Dever::db('shop/info')->find($info['shop_id']);
  282. Dever::load('shop/lib/refund')->set('sell')->apply(1, $shop['id'], $id, false, 3, 0, '未通过审核');
  283. }
  284. }
  285. }
  286. public function setSellOrderStatusMul_commit($id, $name, $data)
  287. {
  288. Dever::config('base')->hook = true;
  289. $status = Dever::param('status', $data);
  290. if ($status == 5) {
  291. # 批量确认收货
  292. $list = explode(',', $id);
  293. if ($list) {
  294. foreach ($list as $k => $v) {
  295. if (is_array($v)) {
  296. $id = $v['id'];
  297. $info = Dever::db('shop/sell_order')->one($id);
  298. } else {
  299. $id = $v;
  300. $info = Dever::db('shop/sell_order')->one($id);
  301. }
  302. if ($info['status'] != 4) {
  303. Dever::alert($info['order_num'] . '该订单无法确认收货');
  304. }
  305. $info['status'] = 4;
  306. Dever::load('shop/lib/sell')->finish($info, $info['shop_id']);
  307. }
  308. }
  309. } elseif ($status == 2) {
  310. # 批量审核
  311. $list = explode(',', $id);
  312. if ($list) {
  313. foreach ($list as $k => $v) {
  314. if (is_array($v)) {
  315. $id = $v['id'];
  316. } else {
  317. $id = $v;
  318. }
  319. Dever::load('shop/lib/sell')->auditOne($id);
  320. }
  321. }
  322. }
  323. }
  324. /**
  325. * 更新信息
  326. *
  327. * @return mixed
  328. */
  329. public function couponUpdate($id, $name, $data)
  330. {
  331. Dever::config('base')->hook = true;
  332. $update = array();
  333. $coupon = Dever::param('coupon', $data);
  334. if ($coupon) {
  335. $temp = is_string($coupon) ? explode(',', $coupon) : $coupon;
  336. $update['method'] = $temp[0];
  337. $update['coupon_id'] = $temp[1];
  338. }
  339. $shop_id = Dever::param('shop_id', $data);
  340. if ($shop_id) {
  341. $shop = Dever::db('shop/info')->find($shop_id);
  342. $update['city'] = $shop['city'];
  343. }
  344. if (isset($update) && $update) {
  345. $update['where_id'] = $id;
  346. Dever::db('shop/coupon')->update($update);
  347. }
  348. }
  349. /**
  350. * 更新信息
  351. *
  352. * @return mixed
  353. */
  354. public function infoUpdate($id, $name, $data)
  355. {
  356. $update = array();
  357. $area = Dever::param('area', $data);
  358. if ($area) {
  359. $temp = is_string($area) ? explode(',', $area) : $area;
  360. $update['province'] = $temp[0];
  361. $update['city'] = $temp[1];
  362. if (isset($temp[2])) {
  363. $update['county'] = $temp[2];
  364. }
  365. if (isset($temp[3])) {
  366. $update['town'] = $temp[3];
  367. }
  368. if (is_array($area)) {
  369. $area = implode(',', $area);
  370. }
  371. $gup['option_shop_id'] = $id;
  372. $gup['set_area'] = $area;
  373. Dever::db('shop/goods_sku')->updates($gup);
  374. Dever::db('shop/sell_order')->updates($gup);
  375. unset($gup['option_shop_id']);
  376. $gup['option_type_id'] = $id;
  377. $gup['option_type'] = 1;
  378. Dever::db('shop/buy_order')->updates($gup);
  379. Dever::db('shop/out_order')->updates($gup);
  380. }
  381. $address = Dever::param('address', $data);
  382. if ($address && isset($update['city'])) {
  383. $geo = Dever::load('shop/lib/info')->geo($update['city'], $address);
  384. $update['lng'] = $geo[0];
  385. $update['lat'] = $geo[1];
  386. $update['map'] = $geo[2];
  387. $update['coord_address'] = $address;
  388. }
  389. /*
  390. $map = Dever::param('map', $data);
  391. if ($map) {
  392. $temp = is_string($map) ? explode(',', $map) : $map;
  393. if (isset($temp[1])) {
  394. $update['lng'] = $temp[1];
  395. $update['lat'] = $temp[2];
  396. $address = Dever::param('address', $data);
  397. $update['coord_address'] = Dever::load('shop/lib/info')->address($temp[1], $temp[2]);
  398. if (!$address && $update['coord_address']) {
  399. $update['address'] = $update['coord_address'];
  400. }
  401. }
  402. }
  403. */
  404. $act = Dever::param('act', $data);
  405. if ($act) {
  406. foreach ($act as $k => $v) {
  407. $w = array();
  408. $w['shop_id'] = $id;
  409. $w['act_id'] = $k;
  410. foreach ($v as $k1 => $v1) {
  411. $w['shop_coupon_id'] = $v1;
  412. $info = Dever::db('shop/coupon_act')->find($w);
  413. if (!$info) {
  414. Dever::db('shop/coupon_act')->insert($w);
  415. }
  416. }
  417. }
  418. }
  419. //Dever::upLinkage($update, $id, $data, 'goods', 'shop/goods', 'shop_id', 'goods_id', 'category_id');
  420. //Dever::upLinkage($update, $id, $data, 'factory', 'shop/factory', 'shop_id', 'factory_id', 'city');
  421. //Dever::upLinkage($update, $id, $data, 'store', 'shop/store', 'shop_id', 'store_id', 'city');
  422. if (isset($update) && $update) {
  423. $update['where_id'] = $id;
  424. Dever::db('shop/info')->update($update);
  425. }
  426. $truename = Dever::param('truename', $data);
  427. $mobile = Dever::param('mobile', $data);
  428. if ($mobile) {
  429. $match = Dever::rule('mobile');
  430. if (preg_match($match, $mobile)) {
  431. $member = Dever::db('shop/member')->one(array('shop_id' => $id, 'mobile' => $mobile));
  432. $update = array();
  433. $update['shop_id'] = $id;
  434. $update['name'] = $truename;
  435. $update['mobile'] = $mobile;
  436. if ($member) {
  437. $update['where_id'] = $member['id'];
  438. Dever::db('shop/member')->update($update);
  439. } else {
  440. Dever::db('shop/member')->insert($update);
  441. }
  442. }
  443. }
  444. }
  445. private function updateParam()
  446. {
  447. }
  448. /**
  449. * 更新商品信息
  450. *
  451. * @return mixed
  452. */
  453. public function goodsUpdate($id, $name, $data)
  454. {
  455. $update = array();
  456. $state = Dever::param('state', $data);
  457. if ($state) {
  458. Dever::config('base')->after = true;
  459. $info = Dever::db('shop/goods')->one($id);
  460. $shop_id = $info['shop_id'];
  461. $shop = Dever::db('shop/info')->one($shop_id);
  462. if ($shop && $shop['goods']) {
  463. $goods = Dever::json_decode($shop['goods']);
  464. if (isset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']])) {
  465. if ($state == 2) {
  466. unset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']]);
  467. }
  468. if (count($goods['level_' . $info['category_id']]['value']) <= 0) {
  469. unset($goods['level_' . $info['category_id']]);
  470. }
  471. } elseif ($state == 1) {
  472. $goods_info = Dever::db('goods/info')->one($info['goods_id']);
  473. $cate = Dever::load('category/api')->string($info['category_id']);
  474. $goods['level_' . $info['category_id']]['id'] = $info['category_id'];
  475. $goods['level_' . $info['category_id']]['name'] = $cate;
  476. $goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']] = array
  477. (
  478. 'id' => $info['goods_id'],
  479. 'name' => $goods_info['name'],
  480. 'state' => 1,
  481. );
  482. }
  483. $set['goods'] = Dever::json_encode($goods);
  484. $set['where_id'] = $shop_id;
  485. Dever::db('shop/info')->update($set);
  486. }
  487. }
  488. }
  489. /**
  490. * 更新库存信息
  491. *
  492. * @return mixed
  493. */
  494. public function skuUpdate($id, $name, $data)
  495. {
  496. $update = array();
  497. $add_num = Dever::param('add_num', $data);
  498. if ($add_num) {
  499. $state = Dever::db('shop/goods_sku')->updateTotal(array('where_id' => $id, 'total_num' => $add_num));
  500. if ($state) {
  501. $state = Dever::db('shop/goods_sku')->update(array('where_id' => $id, 'add_num' => 0));
  502. $info = Dever::db('shop/goods_sku')->one($id);
  503. $goods = Dever::db('shop/goods')->one(array('goods_id' => $info['goods_id'], 'shop_id' => $info['shop_id']));
  504. if ($goods) {
  505. Dever::db('shop/goods')->update(array('where_id' => $goods['id'], 'total_num' => $info['total_num'], 'add_num' => 0));
  506. }
  507. if ($add_num < 0) {
  508. # 记录出库日志
  509. } else {
  510. # 记录入库日志
  511. }
  512. }
  513. }
  514. }
  515. # 获取供货商信息
  516. public function buyInfo($type = '', $type_id = '')
  517. {
  518. if ($type == 1) {
  519. $type_info = Dever::db('shop/info')->one($type_id);
  520. return $type_info['name'] . '('.$type_info['mobile'].')';
  521. } elseif ($type == 2) {
  522. $type_info = Dever::db('store/info')->one($type_id);
  523. $sign = Dever::login($type_id);
  524. $link = Dever::url('home?sign=' . $sign, 'store');
  525. //return $type_info['name'] . '('.$type_info['mobile'].')<br /><a href="'.$link.'" target="_blank">进入仓库管理</a>';
  526. return $type_info['name'] . '('.$type_info['mobile'].')';
  527. } elseif ($type == 3) {
  528. $sign = Dever::login($type_id);
  529. $link = Dever::url('home?sign=' . $sign, 'factory');
  530. $type_info = Dever::db('factory/info')->one($type_id);
  531. //return $type_info['name'] . '('.$type_info['mobile'].')<br /><a href="'.$link.'" target="_blank">进入工厂管理</a>';
  532. return $type_info['name'] . '('.$type_info['mobile'].')';
  533. } else {
  534. return '无';
  535. }
  536. }
  537. /**
  538. * 更新信息
  539. *
  540. * @return mixed
  541. */
  542. public function buyOrderPs($id, $name, $data)
  543. {
  544. $order_id = Dever::param('order_id', $data);
  545. if ($order_id) {
  546. $update['where_id'] = $order_id;
  547. $update['set_status'] = 4;
  548. Dever::db('shop/buy_order')->update($update);
  549. }
  550. }
  551. # 获取门店
  552. public function search_api()
  553. {
  554. return Dever::search('shop/info');
  555. }
  556. # 获取门店
  557. public function search_shop_api()
  558. {
  559. $data = Dever::search('shop/info');
  560. $result = array();
  561. if ($data) {
  562. foreach ($data as $k => $v) {
  563. if (!$v['mid']) {
  564. $data[$k]['name'] .= '('.$v['sid'].')';
  565. $result[] = $data[$k];
  566. }
  567. }
  568. }
  569. return $result;
  570. }
  571. # 获取所有门店
  572. public function search_all_shop_api()
  573. {
  574. $data = Dever::search('shop/info');
  575. $result = array();
  576. if ($data) {
  577. foreach ($data as $k => $v) {
  578. $data[$k]['name'] .= '('.$v['sid'].')';
  579. $result[] = $data[$k];
  580. }
  581. }
  582. return $result;
  583. }
  584. # 获取零售门店
  585. public function search_l_shop_api()
  586. {
  587. $data = Dever::search('shop/info');
  588. $result = array();
  589. if ($data) {
  590. foreach ($data as $k => $v) {
  591. if ($v['type'] == 2) {
  592. $data[$k]['name'] .= '('.$v['sid'].')';
  593. $result[] = $data[$k];
  594. }
  595. }
  596. }
  597. return $result;
  598. }
  599. # 获取环比增长
  600. public function getGoodsHb($num, $day, $goods_id)
  601. {
  602. $where = array('day' => $day, 'goods_id' => $goods_id);
  603. $search = Dever::search_button();
  604. if ($search) {
  605. $where['config']['group'] = $search[0];
  606. $where['config']['col'] = str_replace('|id', '', $search[1]);
  607. }
  608. if ($num < 0) {
  609. $num = 0;
  610. }
  611. $prev = Dever::db('shop/goods_stat')->prev($where);
  612. if ($prev && $num > 0 && $prev['num'] >= 0) {
  613. $n = $prev['num'];
  614. if ($n == 0) {
  615. $n = 1;
  616. }
  617. $hb = round(($num-$prev['num'])/$n, 2)*100;
  618. } else {
  619. $hb = 0;
  620. }
  621. return $hb . '%';
  622. }
  623. public function getUserHb($num, $total, $day)
  624. {
  625. $result = $this->getUserStat($num, $total, 0);
  626. $where = array('day' => $day);
  627. $search = Dever::search_button();
  628. if ($search) {
  629. $where['config']['group'] = $search[0];
  630. $where['config']['col'] = str_replace('|id', '', $search[1]);
  631. }
  632. $hb = 0;
  633. $prev = Dever::db('shop/user_stat')->prev($where);
  634. if ($prev) {
  635. $prev = $this->getUserStat($prev['num'], $prev['total'], $prev['order_num']);
  636. if ($result['fg'] > 0 && $prev['fg'] >= 0) {
  637. $fg = $prev['fg'];
  638. if ($fg == 0) {
  639. $fg = 1;
  640. }
  641. $hb = round(($result['fg']-$prev['fg'])/$fg, 2)*100;
  642. }
  643. }
  644. return $hb . '%';
  645. }
  646. public function getUserStat($num, $total, $order_num)
  647. {
  648. //print_r($info);die;
  649. if ($num && $total) {
  650. $result['fg'] = round($num/$total, 2);
  651. } else {
  652. $result['fg'] = 0;
  653. }
  654. if ($order_num) {
  655. $result['per_num'] = round($order_num/$total, 2);
  656. } else {
  657. $result['per_num'] = 0;
  658. }
  659. return $result;
  660. }
  661. # 获取环比增长
  662. public function getUserRankHb($num, $mobile, $day)
  663. {
  664. $where = array('day' => $day, 'mobile' => $mobile);
  665. $search = Dever::search_button();
  666. if ($search) {
  667. $where['config']['group'] = $search[0];
  668. $where['config']['col'] = str_replace('|id', '', $search[1]);
  669. }
  670. if ($num < 0) {
  671. $num = 0;
  672. }
  673. $prev = Dever::db('shop/user_rank_stat')->prev($where);
  674. if ($prev && $num > 0 && $prev['num'] >= 0) {
  675. $n = $prev['num'];
  676. if ($n == 0) {
  677. $n = 1;
  678. }
  679. $hb = round(($num-$prev['num'])/$n, 2)*100;
  680. } else {
  681. $hb = 0;
  682. }
  683. return $hb . '%';
  684. }
  685. # 确认收货
  686. public function setSellOrderStatus_api()
  687. {
  688. $order_id = Dever::input('order_id');
  689. $info = Dever::db('shop/sell_order')->find($order_id);
  690. if ($info) {
  691. Dever::load('shop/lib/sell')->finish($info, $info['shop_id']);
  692. return 'reload';
  693. } else {
  694. Dever::alert('错误的订单号');
  695. }
  696. }
  697. public function searchName($where)
  698. {
  699. $data = Dever::db('store/info')->like($where);
  700. if (!$data) {
  701. $data = Dever::db('shop/info')->like($where);
  702. }
  703. return $data;
  704. }
  705. public function searchFName($where)
  706. {
  707. $data = Dever::db('store/info')->like($where);
  708. if (!$data) {
  709. $data = Dever::db('factory/info')->like($where);
  710. }
  711. return $data;
  712. }
  713. public function goods_list($id){
  714. $info = Dever::db('shop/sell_order')->find($id);
  715. $res = array();
  716. $goods = Dever::db('shop/sell_order_goods')->getGoods(array('order_id'=>$id));
  717. $data = array();
  718. foreach($goods as $k => $v){
  719. $data[] = Dever::db('goods/info')->fetch('select `name` from churen_goods_info where id = '.$v['goods_id'].' and state =1');
  720. }
  721. $html = '';
  722. if ($data) {
  723. foreach($data as $k => $v){
  724. if (isset($v['name']) && $v['name']) {
  725. $res[] = $v['name'];
  726. } else {
  727. $res[] = '';
  728. }
  729. }
  730. if (count($res) > 3){
  731. $html = $res[0].'<br/>'.$res[1].'<br/>'.$res['2'].'……';
  732. } else {
  733. $html = implode('<br/>',$res);
  734. }
  735. }
  736. return $html;
  737. }
  738. }