Manage.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function getOrderUrl($order_id, $order_num)
  7. {
  8. $url = Dever::load('manage/database')->url('list', $order_id, 'buy_order_goods&project=shop&order_id='.$order_id.'&page_type=1');
  9. $url = '<a href="'.$url.'">'.$order_num.'</a>';
  10. return $url;
  11. }
  12. public function showCash($cash, $p_cash = 0)
  13. {
  14. if (!$cash) {
  15. $cash = 0;
  16. }
  17. if (!$p_cash) {
  18. $p_cash = 0;
  19. }
  20. return $cash - $p_cash;
  21. }
  22. # 获取用户信息
  23. public function user($id)
  24. {
  25. $info = Dever::db('shop/sell_order')->one($id);
  26. if ($info['uid'] && $info['uid'] > 0) {
  27. $user = Dever::db('passport/user')->one($info['uid']);
  28. $result = $user['username'];
  29. if ($info['mobile']) {
  30. $result .= '('.$info['mobile'].')';
  31. }
  32. } else {
  33. $result = $info['mobile'];
  34. }
  35. return $result;
  36. }
  37. # 获取订单信息
  38. public function sell_order($id)
  39. {
  40. $table = array();
  41. $info = Dever::db('shop/sell_order')->one($id);
  42. $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
  43. foreach ($goods as $k => $v) {
  44. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
  45. //print_r($goods_info);die;
  46. $table[$goods_info['name']] = $v['price'];
  47. }
  48. return Dever::table($table);
  49. }
  50. /**
  51. * 更新信息
  52. *
  53. * @return mixed
  54. */
  55. public function upInfo($id, $name, $data)
  56. {
  57. Dever::config('base')->hook = true;
  58. }
  59. /**
  60. * 更新信息
  61. *
  62. * @return mixed
  63. */
  64. public function printInsert($id, $name, $data)
  65. {
  66. Dever::config('base')->hook = true;
  67. $name = Dever::param('name', $data);
  68. $number = Dever::param('number', $data);
  69. $phonenum = Dever::param('phonenum', $data);
  70. $key = Dever::param('key', $data);
  71. if ($number && $key) {
  72. $data = array();
  73. $data['name'] = $name;
  74. $data['number'] = $number;
  75. $data['phonenum'] = $phonenum;
  76. $data['key'] = $key;
  77. $result = Dever::load('mshop/lib/feieyun')->add(array($data));
  78. if (isset($result['no'][0]) && $result['no'][0] && strstr($result['no'][0], '编号不合法')) {
  79. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 10));
  80. } else {
  81. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 1));
  82. }
  83. }
  84. }
  85. /**
  86. * 更新信息
  87. *
  88. * @return mixed
  89. */
  90. public function printUpdate($id, $name, $data)
  91. {
  92. Dever::config('base')->hook = true;
  93. $info = Dever::db('shop/print')->one($id);
  94. $name = Dever::param('name', $data);
  95. $phonenum = Dever::param('phonenum', $data);
  96. if ($info && $name) {
  97. if ($info['status'] == 10) {
  98. $this->printInsert($id, $name, $info);
  99. } else {
  100. Dever::load('mshop/lib/feieyun')->edit($info['number'], $name, $phonenum);
  101. }
  102. }
  103. }
  104. /**
  105. * 打印机状态
  106. *
  107. * @return mixed
  108. */
  109. public function printStatus($status, $sn)
  110. {
  111. return $status >= 10 ? '绑定失败' : Dever::load('mshop/lib/feieyun')->status($sn);
  112. }
  113. /**
  114. * 更新信息
  115. *
  116. * @return mixed
  117. */
  118. public function couponUpdate($id, $name, $data)
  119. {
  120. Dever::config('base')->hook = true;
  121. $update = array();
  122. $coupon = Dever::param('coupon', $data);
  123. if ($coupon) {
  124. $temp = is_string($coupon) ? explode(',', $coupon) : $coupon;
  125. $update['method'] = $temp[0];
  126. $update['coupon_id'] = $temp[1];
  127. }
  128. $shop_id = Dever::param('shop_id', $data);
  129. if ($shop_id) {
  130. $shop = Dever::db('shop/info')->find($shop_id);
  131. $update['city'] = $shop['city'];
  132. }
  133. if (isset($update) && $update) {
  134. $update['where_id'] = $id;
  135. Dever::db('shop/coupon')->update($update);
  136. }
  137. }
  138. /**
  139. * 更新信息
  140. *
  141. * @return mixed
  142. */
  143. public function infoUpdate($id, $name, $data)
  144. {
  145. $update = array();
  146. $area = Dever::param('area', $data);
  147. if ($area) {
  148. $temp = is_string($area) ? explode(',', $area) : $area;
  149. $update['province'] = $temp[0];
  150. $update['city'] = $temp[1];
  151. if (isset($temp[2])) {
  152. $update['county'] = $temp[2];
  153. }
  154. if (isset($temp[3])) {
  155. $update['town'] = $temp[3];
  156. }
  157. }
  158. $map = Dever::param('map', $data);
  159. if ($map) {
  160. $temp = is_string($map) ? explode(',', $map) : $map;
  161. if (isset($temp[1])) {
  162. $update['lng'] = $temp[1];
  163. $update['lat'] = $temp[2];
  164. $address = Dever::param('address', $data);
  165. $update['coord_address'] = Dever::load('shop/lib/info')->address($temp[1], $temp[2]);
  166. if (!$address && $update['coord_address']) {
  167. $update['address'] = $update['coord_address'];
  168. }
  169. }
  170. }
  171. $act = Dever::param('act', $data);
  172. if ($act) {
  173. foreach ($act as $k => $v) {
  174. $w = array();
  175. $w['shop_id'] = $id;
  176. $w['act_id'] = $k;
  177. foreach ($v as $k1 => $v1) {
  178. $w['shop_coupon_id'] = $v1;
  179. $info = Dever::db('shop/coupon_act')->find($w);
  180. if (!$info) {
  181. Dever::db('shop/coupon_act')->insert($w);
  182. }
  183. }
  184. }
  185. }
  186. //Dever::upLinkage($update, $id, $data, 'goods', 'shop/goods', 'shop_id', 'goods_id', 'category_id');
  187. //Dever::upLinkage($update, $id, $data, 'factory', 'shop/factory', 'shop_id', 'factory_id', 'city');
  188. //Dever::upLinkage($update, $id, $data, 'store', 'shop/store', 'shop_id', 'store_id', 'city');
  189. if (isset($update) && $update) {
  190. $update['where_id'] = $id;
  191. Dever::db('shop/info')->update($update);
  192. }
  193. $truename = Dever::param('truename', $data);
  194. $mobile = Dever::param('mobile', $data);
  195. if ($mobile) {
  196. $member = Dever::db('shop/member')->one(array('shop_id' => $id, 'mobile' => $mobile));
  197. $update = array();
  198. $update['shop_id'] = $id;
  199. $update['name'] = $truename;
  200. $update['mobile'] = $mobile;
  201. if ($member) {
  202. $update['where_id'] = $member['id'];
  203. Dever::db('shop/member')->update($update);
  204. } else {
  205. Dever::db('shop/member')->insert($update);
  206. }
  207. }
  208. }
  209. private function updateParam()
  210. {
  211. }
  212. /**
  213. * 更新商品信息
  214. *
  215. * @return mixed
  216. */
  217. public function goodsUpdate($id, $name, $data)
  218. {
  219. $update = array();
  220. $state = Dever::param('state', $data);
  221. if ($state) {
  222. Dever::config('base')->after = true;
  223. $info = Dever::db('shop/goods')->one($id);
  224. $shop_id = $info['shop_id'];
  225. $shop = Dever::db('shop/info')->one($shop_id);
  226. if ($shop && $shop['goods']) {
  227. $goods = Dever::json_decode($shop['goods']);
  228. if (isset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']])) {
  229. if ($state == 2) {
  230. unset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']]);
  231. }
  232. if (count($goods['level_' . $info['category_id']]['value']) <= 0) {
  233. unset($goods['level_' . $info['category_id']]);
  234. }
  235. } elseif ($state == 1) {
  236. $goods_info = Dever::db('goods/info')->one($info['goods_id']);
  237. $cate = Dever::load('category/api')->string($info['category_id']);
  238. $goods['level_' . $info['category_id']]['id'] = $info['category_id'];
  239. $goods['level_' . $info['category_id']]['name'] = $cate;
  240. $goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']] = array
  241. (
  242. 'id' => $info['goods_id'],
  243. 'name' => $goods_info['name'],
  244. 'state' => 1,
  245. );
  246. }
  247. $set['goods'] = Dever::json_encode($goods);
  248. $set['where_id'] = $shop_id;
  249. Dever::db('shop/info')->update($set);
  250. }
  251. }
  252. }
  253. /**
  254. * 更新库存信息
  255. *
  256. * @return mixed
  257. */
  258. public function skuUpdate($id, $name, $data)
  259. {
  260. $update = array();
  261. $add_num = Dever::param('add_num', $data);
  262. if ($add_num) {
  263. $state = Dever::db('shop/goods_sku')->updateTotal(array('where_id' => $id, 'total_num' => $add_num));
  264. if ($state) {
  265. $state = Dever::db('shop/goods_sku')->update(array('where_id' => $id, 'add_num' => 0));
  266. $info = Dever::db('shop/goods_sku')->one($id);
  267. $goods = Dever::db('shop/goods')->one(array('goods_id' => $info['goods_id'], 'shop_id' => $info['shop_id']));
  268. if ($goods) {
  269. Dever::db('shop/goods')->update(array('where_id' => $goods['id'], 'total_num' => $info['total_num'], 'add_num' => 0));
  270. }
  271. if ($add_num < 0) {
  272. # 记录出库日志
  273. } else {
  274. # 记录入库日志
  275. }
  276. }
  277. }
  278. }
  279. # 获取供货商信息
  280. public function buyInfo($type = '', $type_id = '')
  281. {
  282. if ($type == 1) {
  283. $type_info = Dever::db('shop/info')->one($type_id);
  284. return $type_info['name'] . '('.$type_info['mobile'].')';
  285. } elseif ($type == 2) {
  286. $type_info = Dever::db('store/info')->one($type_id);
  287. return $type_info['name'] . '('.$type_info['mobile'].')';
  288. } elseif ($type == 3) {
  289. $type_info = Dever::db('factory/info')->one($type_id);
  290. return $type_info['name'] . '('.$type_info['mobile'].')';
  291. } else {
  292. return '无';
  293. }
  294. }
  295. /**
  296. * 更新信息
  297. *
  298. * @return mixed
  299. */
  300. public function buyOrderPs($id, $name, $data)
  301. {
  302. $order_id = Dever::param('order_id', $data);
  303. if ($order_id) {
  304. $update['where_id'] = $order_id;
  305. $update['set_status'] = 4;
  306. Dever::db('shop/buy_order')->update($update);
  307. }
  308. }
  309. # 获取门店
  310. public function search_api()
  311. {
  312. return Dever::search('shop/info');
  313. }
  314. }