Data.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <?php
  2. namespace Mshop\Src;
  3. use Dever;
  4. use Mshop\Lib\Core;
  5. class Data extends Core
  6. {
  7. public function home()
  8. {
  9. $day = Dever::input('day');
  10. if (!$day) {
  11. $day = date('Y-m-d');
  12. }
  13. $where['start'] = Dever::maketime($day . ' 00:00:00');
  14. $where['end'] = Dever::maketime($day . ' 23:59:59');
  15. $where['shop_id'] = $this->shop_id;
  16. $where['status'] = '1,2,3,4';
  17. $this->data['num_order'] = round(Dever::db('shop/sell_order')->getOrderNum($where), 2);
  18. $cash = Dever::db('shop/sell_order')->getCashNum($where);
  19. if ($cash) {
  20. $this->data['num_cash'] = $cash['total'];
  21. }
  22. if (!$this->data['num_cash']) {
  23. $this->data['num_cash'] = 0;
  24. }
  25. $goods = Dever::db('shop/sell_order')->getGoodsNum($where);
  26. if ($goods) {
  27. $this->data['num_goods'] = $goods['total'];
  28. }
  29. if (!$this->data['num_goods']) {
  30. $this->data['num_goods'] = 0;
  31. }
  32. $this->data['num_cash'] = round($this->data['num_cash'], 2);
  33. $this->data['num_goods'] = round($this->data['num_goods'], 2);
  34. return $this->data;
  35. }
  36. # 销售订单列表
  37. public function sell_order()
  38. {
  39. return Dever::load('shop/lib/sell')->set(2, 1)->getList($this->shop_id);
  40. }
  41. # 查看订单详情
  42. public function order_view()
  43. {
  44. $order_id = Dever::input('order_id');
  45. return Dever::load('shop/lib/sell')->set(2, 2)->getView($this->shop_id, $order_id);
  46. }
  47. # 通知用户取件或者配送
  48. public function notice()
  49. {
  50. $order_id = Dever::input('order_id');
  51. $info = Dever::db('shop/sell_order')->find('id' => $order_id));
  52. if ($info && $info['shop_id'] == $this->shop_id && $info['status'] < 3) {
  53. $state = Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => 3, 'operdate' => time()));
  54. # 给用户发消息
  55. if ($info['uid'] && $info['uid'] > 0) {
  56. $shop = Dever::db('shop/info')->one($info['shop_id']);
  57. $msg_param['type'] = 1;//消息类型1是订单消息
  58. $msg_param['id'] = $info['id'];
  59. $msg_param['name'] = $shop['name'];
  60. $msg_param = Dever::json_encode($msg_param);
  61. if ($info['method'] == 1) {
  62. $msg = '您有一件自提商品已完成配货,请尽快到指定门店使用取件码取货,取件码:' . $info['code'];
  63. $name = '取货通知';
  64. } else {
  65. $msg = '您有一件外送商品已开始配送,收货时请将取件码提供给配送员核实货品信息,取件码::' . $info['code'];
  66. $name = '配送通知';
  67. # 分配配送商家
  68. Dever::load('shop/lib/sell')->updatePs($info, 2);
  69. }
  70. Dever::load('message/lib/data')->push(-1, $info['uid'], $name, $msg, 1, 1, false, $msg_param);
  71. }
  72. return 'ok';
  73. } else {
  74. Dever::alert('您没有权限');
  75. }
  76. }
  77. # 核销取件码,完成
  78. public function finish()
  79. {
  80. $code = Dever::input('code');
  81. $order_id = Dever::input('order_id');
  82. $info = Dever::db('shop/sell_order')->find(array('code' => $code, 'id' => $order_id));
  83. if ($info && $info['shop_id'] == $this->shop_id && $infn['status'] <= 3) {
  84. $state = Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => 4, 'operdate' => time()));
  85. # 给用户发消息
  86. if ($info['uid'] && $info['uid'] > 0) {
  87. $shop = Dever::db('shop/info')->one($info['shop_id']);
  88. $msg_param['type'] = 1;//消息类型1是订单消息
  89. $msg_param['id'] = $info['id'];
  90. $msg_param['name'] = $shop['name'];
  91. $msg_param = Dever::json_encode($msg_param);
  92. $msg = '您有一笔订单已签收,祝您用餐愉快~';
  93. Dever::load('message/lib/data')->push(-1, $info['uid'], '订单完成通知', $msg, 1, 1, false, $msg_param);
  94. }
  95. if ($info['method'] == 2) {
  96. Dever::load('shop/lib/sell')->updatePs($info, 3);
  97. }
  98. return 'ok';
  99. } else {
  100. Dever::alert('您没有权限核销');
  101. }
  102. }
  103. # 门店全部退款
  104. public function order_tui()
  105. {
  106. $order_id = Dever::input('order_id');
  107. $status = Dever::input('status');
  108. if ($status != 1 && $status != 2) {
  109. Dever::alert('当前订单状态不允许退货退款');
  110. }
  111. if ($status == 1) {
  112. $status = 7;
  113. } elseif ($status == 2) {
  114. $status = 8;
  115. }
  116. $desc = Dever::input('desc');
  117. return Dever::load('shop/lib/sell')->set(2, 2)->tui($this->shop_id, $order_id, $status, $desc);
  118. }
  119. # 门店部分退款信息
  120. public function order_tui_one_info()
  121. {
  122. $order_id = Dever::input('order_id');
  123. $order_goods_id = Dever::input('order_goods_id');
  124. return Dever::load('shop/lib/sell')->set(2, 2)->tui_one_info($this->shop_id, $order_id, $order_goods_id);
  125. }
  126. # 门店部分退款
  127. public function order_tui_one()
  128. {
  129. $order_id = Dever::input('order_id');
  130. $order_goods_id = Dever::input('order_goods_id');
  131. $num = Dever::input('num');
  132. $status = Dever::input('status');
  133. $desc = Dever::input('desc');
  134. if ($status != 1 && $status != 2) {
  135. Dever::alert('当前订单状态不允许退货退款');
  136. }
  137. if ($status == 1) {
  138. $status = 3;
  139. } elseif ($status == 2) {
  140. $status = 4;
  141. }
  142. return Dever::load('shop/lib/sell')->set(2, 2)->tui_one($this->shop_id, $order_id, $order_goods_id, $num, $status, $desc);
  143. }
  144. # 根据店铺获取商品列表
  145. public function getGoods()
  146. {
  147. return Dever::load('shop/lib/goods')->getList();
  148. }
  149. # 获取店铺的优惠券
  150. public function getCoupon()
  151. {
  152. $this->data = Dever::db('shop/coupon')->getAllPage(array('shop_id' => $this->shop_id));
  153. if ($this->data) {
  154. $time = time();
  155. foreach ($this->data as $k => $v) {
  156. $this->data[$k]['info'] = Dever::db('goods/coupon')->find($v['coupon_id']);
  157. $this->data[$k]['shop'] = array();
  158. $coupon = Dever::db('shop/coupon')->select(array('coupon_id' => $v['coupon_id'], 'city' => $v['city']));
  159. foreach ($coupon as $k1 => $v1) {
  160. $shop = Dever::db('shop/info')->getOne(array('id' => $v1['shop_id'], 'city' => $v['city'], 'coupon_city' => 1));
  161. if ($shop) {
  162. $this->data[$k]['shop'][] = $shop;
  163. if ($k1 > 0) {
  164. $city = Dever::db('area/city')->find($v['city']);
  165. $this->data[$k]['shop_name'] = $city['name'] . '多店通用';
  166. } else {
  167. $this->data[$k]['shop_name'] = $shop['name'];
  168. }
  169. }
  170. }
  171. if (!$this->data[$k]['shop']) {
  172. $shop = Dever::db('shop/info')->getOne($v['shop_id']);
  173. $this->data[$k]['shop'][] = $shop;
  174. $this->data[$k]['shop_name'] = $shop['name'];
  175. }
  176. }
  177. }
  178. return $this->data;
  179. }
  180. # 赠送优惠券
  181. public function giveCoupon()
  182. {
  183. $coupon_id = Dever::input('coupon_id');
  184. $coupon = explode(',', $coupon_id);
  185. $num = Dever::input('num');
  186. $coupon_num = explode(',', $num);
  187. $order_id = Dever::input('order_id');
  188. $info = Dever::db('shop/sell_order')->find(array('shop_id' => $this->shop_id, 'id' => $order_id));
  189. if ($info['uid'] && $info['uid'] > 0) {
  190. foreach ($coupon as $k => $v) {
  191. $num = isset($coupon_num[$k]) ? $coupon_num[$k] : 1;
  192. Dever::load('shop/lib/coupon')->getOne($info['uid'], $this->shop, $v, $num, false);
  193. }
  194. }
  195. return 'ok';
  196. }
  197. # 获取购物车的数据
  198. public function getCart()
  199. {
  200. $where['shop_id'] = $this->shop_id;
  201. $this->data['cart'] = Dever::db('shop/shop_cart')->select($where);
  202. if ($this->data['cart']) {
  203. foreach ($this->data['cart'] as $k => $v) {
  204. $this->data['cart'][$k]['goods'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
  205. if (isset($this->data['cart'][$k]['goods']['sku_id'])) {
  206. $this->data['cart'][$k]['price_id'] = $this->data['cart'][$k]['goods']['sku_id'];
  207. }
  208. }
  209. }
  210. return $this->data['cart'];
  211. }
  212. # 加入到购物车
  213. public function addCart()
  214. {
  215. $where['shop_id'] = $this->shop_id;
  216. $where['goods_id'] = Dever::input('goods_id');
  217. $where['sku_id'] = Dever::input('price_id');
  218. if (!$where['goods_id']) {
  219. Dever::alert('错误的商品');
  220. }
  221. $info = Dever::db('shop/shop_cart')->find($where);
  222. $where['num'] = Dever::input('num');
  223. if (!$info) {
  224. # 验证库存
  225. Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);
  226. $state = Dever::db('shop/shop_cart')->insert($where);
  227. } else {
  228. $where['num'] += $info['num'];
  229. # 验证库存
  230. Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);
  231. $where['where_id'] = $info['id'];
  232. $state = Dever::db('shop/shop_cart')->update($where);
  233. }
  234. return $this->getCart();
  235. }
  236. # 清空购物车
  237. public function dropCart()
  238. {
  239. $where['shop_id'] = $this->shop_id;
  240. $state = Dever::db('shop/shop_cart')->delete($where);
  241. return $this->alert($state);
  242. }
  243. # 更新购物车数量
  244. public function upCart()
  245. {
  246. $where['shop_id'] = $this->shop_id;
  247. $where['id'] = Dever::input('cart_id');
  248. $status = Dever::input('status', 1);
  249. $type = Dever::input('type', 1);
  250. $num = Dever::input('num');
  251. $info = Dever::db('shop/shop_cart')->find($where);
  252. $state = false;
  253. if ($info) {
  254. if ($type == 1) {
  255. $num = $info['num'] + $num;
  256. } else {
  257. $num = $info['num'] - $num;
  258. }
  259. $where = array();
  260. $where['where_id'] = $info['id'];
  261. if ($num <= 0) {
  262. $state = Dever::db('shop/shop_cart')->delete($info['id']);
  263. } else {
  264. $where['status'] = $status;
  265. $where['num'] = $num;
  266. # 验证库存
  267. $total = Dever::load('shop/lib/info')->checkTotal($num, $info['goods_id'], $this->shop_id, $info['sku_id']);
  268. if ($where['num'] > $total) {
  269. # 库存不足
  270. $where['num'] = $total;
  271. $state = Dever::db('shop/shop_cart')->update($where);
  272. return array('cart' => 2, 'data' => $total);
  273. }
  274. $state = Dever::db('shop/shop_cart')->update($where);
  275. }
  276. }
  277. return array('cart' => 1, 'data' => $this->getCart());
  278. }
  279. # 确认订单页面
  280. public function confirm()
  281. {
  282. $this->data['shop'] = $this->shop;
  283. Dever::load('shop/lib/sell')->goods($this->data);
  284. Dever::load('shop/lib/sell')->coupon($this->data);
  285. return $this->data;
  286. }
  287. # 开始下单
  288. public function pay()
  289. {
  290. $refer = Dever::input('refer');
  291. $cart = Dever::input('cart', 2);
  292. $address_id = Dever::input('address_id');
  293. $invoice_id = Dever::input('invoice_id');
  294. $pay_type = Dever::input('pay_type', 1);
  295. $mobile = Dever::input('mobile');
  296. $cash = Dever::input('cash');
  297. Dever::setInput('pay_method', 2);
  298. if (!$mobile) {
  299. Dever::alert('手机号不能为空');
  300. }
  301. $info = Dever::input('info');
  302. $this->data['shop'] = $this->shop;
  303. Dever::load('shop/lib/sell')->goods($this->data);
  304. Dever::load('shop/lib/sell')->coupon($this->data, 2);
  305. if ($this->data['pay_method'] > 1) {
  306. $cart = false;
  307. }
  308. if (!$this->data['coupon_id'] && $this->data['price'] <= 0) {
  309. Dever::alert('已售空');
  310. }
  311. if ($this->data['method'] == 2 && !$address_id) {
  312. Dever::alert('收货地址不能为空');
  313. }
  314. if (!isset($this->data['card'])) {
  315. $this->data['card'] = false;
  316. }
  317. $this->user = array
  318. (
  319. 'id' => -1,
  320. 'mobile' => $mobile,
  321. );
  322. if ($cash) {
  323. $this->data['price'] -= $cash;
  324. }
  325. $pay = Dever::load('shop/lib/sell')->pay($this->data['method'], $this->data['pay_method'], $pay_type, $this->user, $this->shop, $this->data['name'], $this->data['num'], $this->data['list'], $this->data['price'], $cash, $address_id, $invoice_id, $info, $this->data['card'], $this->data['coupon_id'], $this->data['user_coupon_id'], $this->data['coupon_cash'], $cart, 4, $refer);
  326. return $pay;
  327. }
  328. # 再次付款
  329. public function r_pay()
  330. {
  331. $refer = Dever::input('refer');
  332. $order_id = Dever::input('order_id');
  333. $pay = Dever::load('shop/lib/sell')->rpay($order_id, 4, $refer);
  334. return $pay;
  335. }
  336. # 销量统计
  337. }