123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812 |
- <?php
- namespace Shop\Lib;
- use Dever;
- class Sell
- {
-
- public $type = 1;
-
- public $view = 1;
-
- public $config = array();
-
- public $table = 'shop/sell_order';
- public function __construct()
- {
- $this->config = Dever::db($this->table)->config;
- }
-
- public function set($type, $view)
- {
- $this->type = $type;
- $this->view = $view;
- return $this;
- }
-
- public function where($id)
- {
- $where = array();
- if ($this->type == 1) {
- $where['uid'] = $id;
- } elseif ($this->type == 2) {
- $where['shop_id'] = $id;
- }
- if (!$where) {
- Dever::alert('参数错误');
- }
- return $where;
- }
-
- public function getList($id)
- {
- $result = array();
- $where = $this->where($id);
- $mobile = Dever::input('mobile');
- if ($mobile) {
- $where['mobile'] = $mobile;
- }
- $status = Dever::input('status');
- if ($status) {
- $where['status'] = $status;
- }
- $method = Dever::input('method');
- if ($method) {
- $where['method'] = $method;
- }
- $pay_method = Dever::input('pay_method');
- if ($pay_method) {
- $where['pay_method'] = $pay_method;
- }
- $result['search_value'] = $where;
- $result['search_value']['day'] = $day = Dever::input('day');
- if ($day) {
- $where['start'] = Dever::maketime($day . ' 00:00:00');
- $where['end'] = Dever::maketime($day . ' 23:59:59');
- }
- $result['order'] = Dever::db($this->table)->getAll($where);
- if ($result['order']) {
- foreach ($result['order'] as $k => $v) {
- $result['order'][$k] = $this->getInfo($v);
- }
- }
- $result['search'] = array();
- $result['search']['status'] = array
- (
- array('value' => 1, 'name' => '待支付'),
- array('value' => 2, 'name' => '待处理'),
- );
- if ($method == 1) {
- $result['search']['status'][] = array('value' => 3, 'name' => '待自提');
- } elseif ($method == 2) {
- $result['search']['status'][] = array('value' => 3, 'name' => '配送中');
- } else {
- $result['search']['status'][] = array('value' => 3, 'name' => '待自提');
- $result['search']['status'][] = array('value' => 3, 'name' => '配送中');
- }
- $result['search']['status'][] = array('value' => 8, 'name' => '退款');
- $result['search']['status'][] = array('value' => '5,6', 'name' => '已完成');
- $result['search']['status'][] = array('value' => '7,11', 'name' => '已取消');
- $result['search']['method'] = array
- (
- array('value' => 1, 'name' => '自提'),
- array('value' => 2, 'name' => '配送')
- );
- $result['search']['pay_method'] = array
- (
- array('value' => 1, 'name' => '平台结算'),
- array('value' => 2, 'name' => '门店代下单')
- );
- return $result;
- }
-
- public function getView($id, $order_id, $show = true)
- {
- $where = $this->where($id);
- $where['id'] = $order_id;
- $result = Dever::db($this->table)->find($where);
- if (!$result) {
- Dever::alert('订单不存在');
- }
- if ($show) {
- $result = $this->getInfo($result);
- }
- return $result;
- }
-
- public function getInfo($info)
- {
- $info['time'] = 0;
- if ($info['status'] == 1) {
-
- $m = 900;
-
- $info['time'] = time() - $info['cdate'];
- if ($info['time'] >= $m) {
-
- $info['time'] = -1;
- Dever::db($this->table)->update(array('where_id' => $info['id'], 'status' => 11));
- $info['status'] = 11;
- } else {
- $info['time'] = $m - $info['time'];
- }
- }
- $info['status_name'] = $this->config['status'][$info['status']];
- $info['method_name'] = $this->config['method'][$info['method']];
- $info['pay_method_name'] = $this->config['pay_method'][$info['pay_method']];
- $info['pay_type_name'] = $this->config['pay_type'][$info['pay_type']];
- if (!$info['coupon_cash']) {
- $info['coupon_cash'] = 0;
- }
- if (!$info['refund_cash']) {
- $info['refund_cash'] = 0;
- }
- if (!$info['ps_cash']) {
- $info['ps_cash'] = 0;
- }
- if (!$info['ps_cash']) {
- $info['ps_cash'] = 0;
- }
- if (!$info['wallet_cash']) {
- $info['wallet_cash'] = 0;
- } else {
- $info['wallet_cash'] = round($info['wallet_cash'], 2);
- }
- if (!$info['card_code_cash']) {
- $info['card_code_cash'] = 0;
- } else {
- $info['card_code_cash'] = round($info['card_code_cash'], 2);
- }
- $info['card_name'] = '';
- if ($info['card_code_id'] > 0) {
- $config = Dever::db('main/sell_config')->find();
- $info['card_name'] = $config['card_name'];
- $card_code = Dever::db('card/code')->find($info['card_code_id']);
- if ($card_code) {
- $card_info = Dever::db('card/info')->find($card_code['card_id']);
- if ($card_info) {
- $card_type = Dever::db('card/type')->find($card_info['type_id']);
- $card = substr($card_code['card'], -4);
- $info['card_name'] .= '('.$card_type['name'].$card.')';
- }
- }
- }
-
- if ($this->type == 1) {
- if ($info['status'] == 2) {
- $info['status_name'] = '支付成功';
- }
- if ($info['status'] == 3) {
- if ($info['method'] == 1) {
- $info['status_name'] = '待自提';
- } else {
- $info['status_name'] = '配送中';
- }
- }
- } elseif ($this->type == 2) {
- if ($info['status'] == 2) {
- $info['status_name'] = '待处理';
- }
- if ($info['status'] == 3) {
- if ($info['method'] == 1) {
- $info['status_name'] = '待自提';
- } else {
- $info['status_name'] = '配送中';
- }
- }
- }
- if ($info['method'] == 2) {
- $info['ps_info'] = Dever::db('shop/sell_order_ps')->find(array('order_id' => $info['id']));
- if ($info['ps_info']) {
- $info['ps_info']['service'] = Dever::array_decode($info['ps_info']['service']);
- $info['ps_info']['cdate'] = date('Y-m-d H:i', $info['ps_info']['cdate']);
- if ($info['ps_info']['qu_date']) {
- $info['ps_info']['qu_date'] = date('Y-m-d H:i', $info['ps_info']['qu_date']);
- }
- if ($info['ps_info']['qs_date']) {
- $info['ps_info']['qs_date'] = date('Y-m-d H:i', $info['ps_info']['qs_date']);
- }
- $status = Dever::db('shop/sell_order_ps')->config['status'];
- $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
- if ($info['ps_info']['service']) {
- foreach ($info['ps_info']['service'] as $k => $v) {
- if (isset($v['order_num']) && $v['order_num']) {
- $info['ps_info']['service'][$k]['service_name'] = '商家自送';
- if ($v['service_id'] > 0) {
- $service = Dever::db('shop/service')->find($v['service_id']);
- $info['ps_info']['service'][$k]['service_name'] = $service['name'];
- }
- } else {
- unset($info['ps_info']['service'][$k]);
- }
- }
- }
- }
- }
- $info['goods'] = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
- if ($info['uid'] && $info['uid'] > 0) {
- $info['user'] = Dever::load('passport/api')->info($info['uid']);
- }
-
- $info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
- $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
- if ($info['operdate']) {
- $info['operdate'] = date('Y-m-d H:i', $info['operdate']);
- } else {
- $info['operdate'] = '';
- }
- if ($info['fdate']) {
- $info['fdate'] = date('Y-m-d H:i', $info['fdate']);
- } else {
- $info['fdate'] = '';
- }
- $goods_status = Dever::db('shop/sell_order_goods')->config['status'];
- if ($info['address_id']) {
- $info['address'] = Dever::db('passport/address')->find($info['address_id']);
- }
- if ($this->view == 2) {
- foreach ($info['goods'] as $k => $v) {
- $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
- $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
- }
- if ($info['invoice_id']) {
- $info['invoice'] = Dever::db('passport/invoice')->find($info['invoice_id']);
- }
- if ($info['user_coupon_id']) {
- $coupon = Dever::db('shop/user_coupon')->find($info['user_coupon_id']);
- if ($coupon) {
- $info['coupon'] = Dever::db('goods/coupon')->find($coupon['coupon_id']);
- }
- }
- } else {
- foreach ($info['goods'] as $k => $v) {
- $goods = Dever::db('goods/info')->one($v['goods_id']);
- $info['goods'][$k]['name'] = $goods['name'];
- $info['goods'][$k]['cover'] = $goods['cover'];
- $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
- }
- }
- return $info;
- }
-
- public function cancel($id, $order_id)
- {
- $data = $this->getView($id, $order_id, false);
- if ($data['status'] == 1) {
- $state = Dever::db('shop/sell_order')->update(array('where_id' => $data['id'], 'status' => 7, 'operdate' => time()));
- if ($state) {
- if ($data['user_coupon_id']) {
-
- Dever::db('shop/user_coupon')->update(array('where_id' => $data['user_coupon_id'], 'status' => 1));
- }
- if (isset($data['card_code_id']) && $data['card_code_id'] && $data['card_code_cash'] > 0) {
-
- Dever::db('card/code')->decUseCash(array('where_id' => $data['card_code_id'], 'set_use_cash' => $data['card_code_cash']));
- } elseif (isset($data['wallet_cash']) && $data['wallet_cash'] && $data['wallet_cash'] > 0) {
-
-
- }
- $this->updateSell($data, 2);
- }
- return 'ok';
- } else {
- Dever::alert('当前订单状态不允许取消');
- }
- }
-
- public function coupon(&$data, $type = 1)
- {
- $user_coupon_id = Dever::input('user_coupon_id');
- $shop_coupon_id = Dever::input('shop_coupon_id');
- $data['user_coupon_id'] = 0;
- $data['coupon_id'] = 0;
- $data['coupon_cash'] = 0;
- if ($data['pay_method'] == 3) {
- return $data;
- }
- if ($type == 1) {
- if (isset($data['uid']) && $data['uid'] > 0) {
-
-
- $coupon = Dever::db('shop/user_coupon')->getAll(array('uid' => $data['uid'], 'city' => $data['shop']['city'], 'status' => 1, 'edate' => time()));
- if ($coupon) {
- foreach ($coupon as $k => $v) {
- $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
- if ($coupon_info) {
- if ($v['shop_id'] != $data['shop']['id'] && $coupon_info['method'] == 3) {
-
- continue;
- }
- $kou = false;
- if ($coupon_info['type'] == 1) {
-
- if ($data['price'] >= $coupon_info['total_cash']) {
- $kou = true;
- }
- } else {
- $kou = true;
- }
- if ($kou) {
- $coupon_info['user_coupon_id'] = $v['id'];
- $coupon_info['uid'] = $v['uid'];
- $coupon_info['edate'] = date('Y-m-d', $v['edate']);
- $coupon_info['shop_id'] = $v['shop_id'];
- $coupon_info['coupon_id'] = $v['coupon_id'];
- $coupon_info['city'] = $v['city'];
- $coupon_info = Dever::load('shop/lib/coupon')->getShop($coupon_info, $data['shop'], false);
- $data['coupon'][] = $coupon_info;
- if (!$user_coupon_id && $data['coupon_cash'] <= $coupon_info['cash']) {
- $data['user_coupon_id'] = $v['id'];
- $data['coupon_id'] = $coupon_info['id'];
- $data['coupon_cash'] = $coupon_info['cash'];
- }
- }
- }
- }
- }
- } else {
- $coupon = Dever::db('shop/coupon')->getAll(array('shop_id' => $data['shop']['id']));
- if ($coupon) {
- foreach ($coupon as $k => $v) {
- $coupon_info = Dever::db('goods/coupon')->find($v['coupon_id']);
- $kou = false;
- if ($coupon_info['type'] == 1) {
-
- if ($data['price'] >= $coupon_info['total_cash']) {
- $kou = true;
- }
- } else {
- $kou = true;
- }
- if ($kou) {
- $coupon_info['shop_id'] = $v['shop_id'];
- $coupon_info['shop_coupon_id'] = $v['id'];
- $coupon_info['coupon_id'] = $v['coupon_id'];
- $coupon_info['city'] = $v['city'];
- $coupon_info = Dever::load('shop/lib/coupon')->getShop($coupon_info, $data['shop'], false);
- $data['coupon'][] = $coupon_info;
- }
- }
- }
- }
- }
- if ($user_coupon_id && isset($data['uid']) && $data['uid'] > 0) {
-
- if ($data['price'] <= 0) {
- Dever::alert('付款价格错误');
- }
- $coupon = Dever::db('shop/user_coupon')->find(array('uid' => $data['uid'], 'id' => $user_coupon_id, 'status' => 1));
- if (!$coupon) {
- Dever::alert('优惠券不可用');
- }
- if (time() > $coupon['edate']) {
- Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 3));
- Dever::alert('优惠券已过期');
- }
- $goods_coupon = Dever::db('goods/coupon')->find($coupon['coupon_id']);
- if (!$goods_coupon) {
- Dever::alert('优惠券不可用');
- }
- if ($coupon['shop_id'] != $data['shop']['id']) {
- if ($goods_coupon['method'] == 3) {
- Dever::alert('优惠券不可用');
- } else {
- $coupon_info = Dever::db('shop/coupon')->find(array('shop_id' => $coupon['shop_id'], 'coupon_id' => $coupon['coupon_id'], 'city' => $coupon['city']));
- if (!$coupon_info) {
- Dever::alert('优惠券不可用');
- }
- }
- }
- if ($goods_coupon['type'] == 2 && $data['price'] < $goods_coupon['total_cash']) {
- Dever::alert('优惠券不可用');
- }
- $data['user_coupon_id'] = $user_coupon_id;
- $data['coupon_id'] = $goods_coupon['id'];
- $data['coupon_cash'] = $goods_coupon['cash'];
- } elseif ($shop_coupon_id) {
-
- if ($data['price'] <= 0) {
- Dever::alert('付款价格错误');
- }
- $coupon_info = Dever::db('shop/coupon')->find(array('shop_id' => $data['shop']['id'], 'id' => $shop_coupon_id));
- if (!$coupon_info) {
- Dever::alert('优惠券不可用');
- }
- $goods_coupon = Dever::db('goods/coupon')->find($coupon_info['coupon_id']);
- if (!$goods_coupon) {
- Dever::alert('优惠券不可用');
- }
- if ($goods_coupon['type'] == 2 && $data['price'] < $goods_coupon['total_cash']) {
- Dever::alert('优惠券不可用');
- }
- $data['user_coupon_id'] = -1;
- $data['coupon_id'] = $goods_coupon['id'];
- $data['coupon_cash'] = $goods_coupon['cash'];
- }
- if (isset($data['coupon_cash']) && $data['coupon_cash'] > 0) {
-
- if (isset($data['list']) && $data['list']) {
- foreach ($data['list'] as $k => $v) {
- $data['list'][$k]['coupon_id'] = $data['coupon_id'];
- $data['list'][$k]['user_coupon_id'] = $data['user_coupon_id'];
- $data['list'][$k]['coupon_cash'] = round(($v['price'] * $v['buy_num'])/$data['price'], 2) * $data['coupon_cash'];
- }
- }
- $data['price'] -= $data['coupon_cash'];
- }
-
- $card = Dever::input('card');
- $wallet = Dever::input('wallet');
- if ($data['price'] > 0 && isset($data['uid']) && $data['uid'] > 0) {
- if ($card) {
-
- $check = Dever::db('card/code')->find($card);
- if ($check['dh_uid'] == $data['uid']) {
- if (!$check['total_cash']) {
- $card_info = Dever::db('card/info')->find($check['card_id']);
- $check['total_cash'] = $card_info['value'];
- }
- if (!$check['use_cash']) {
- $check['use_cash'] = 0;
- }
- $card_cash = $check['total_cash'] - $check['use_cash'];
- if ($card_cash > 0) {
- $data['card'] = array();
- $data['card']['id'] = $check['id'];
- $data['card']['card'] = $check['card'];
- if ($card_cash >= $data['price']) {
- $data['card']['cash'] = $data['price'];
- $data['price'] = 0;
- } else {
- $data['card']['cash'] = $card_cash;
- $data['price'] -= $data['card']['cash'];
- }
- $data['card']['cash'] = round($data['card']['cash'], 2);
- }
- }
- } elseif ($wallet && $wallet > 0) {
- $data['score'] = Dever::load('score/lib/core')->getUserScore($data['uid']);
- }
- }
- if ($data['price'] < 0) {
- $data['price'] = 0;
- }
- $data['price'] = round($data['price'], 2);
- return $data;
- }
-
- public function card($uid, $shop)
- {
- $card = Dever::input('card');
- $pwd = Dever::input('pwd');
- if (!$card) {
- Dever::alert('卡号/密码错误');
- }
- if (!$pwd) {
- Dever::alert('卡号/密码错误');
- }
- $data = Dever::db('goods/card_code')->find(array('card' => $card, 'pwd' => $pwd));
- if (!$data) {
- Dever::alert('卡号/密码错误');
- }
- $info = Dever::db('goods/card')->find($data['card_id']);
- if (!$info || ($info && $info['status'] != 1)) {
- Dever::alert('卡号/密码错误');
- }
- if ($data['uid'] && $data['uid'] > 0) {
- if ($data['uid'] != $uid) {
- Dever::alert('礼品卡已被领取');
- }
- if (time() > $data['edate']) {
-
- $card_update['where_id'] = $data['id'];
- $card_update['status'] = 5;
- Dever::db('goods/card_code')->update($card_update);
- Dever::alert('礼品卡已失效');
- }
- } else {
- if (time() > $data['edate']) {
-
- $card_update['where_id'] = $data['id'];
- $card_update['uid'] = $uid;
- $card_update['status'] = 5;
- if ($shop) {
- $card_update['shop_id'] = $shop['id'];
- }
- Dever::db('goods/card_code')->update($card_update);
- Dever::alert('礼品卡已失效');
- } else {
-
- $card_update['where_id'] = $data['id'];
- $card_update['status'] = 2;
- $card_update['uid'] = $uid;
- $card_update['ddate'] = time();
- if ($shop) {
- $card_update['shop_id'] = $shop['id'];
- }
- Dever::db('goods/card_code')->update($card_update);
- }
- }
- $data = Dever::db('goods/card_code')->find($data['id']);
- $data['goods'] = $info['goods'];
- return $data;
- }
-
- public function goods(&$data)
- {
-
- $data['method'] = Dever::input('method', 1);
- $data['pay_method'] = Dever::input('pay_method');
- if ($data['pay_method'] == 3) {
- $data['card'] = $this->card($data['uid'], $data['shop']);
- $goods = Dever::array_decode($data['card']['goods']);
- $goods_id = array();
- $num = array();
- $sku_id = array();
- foreach ($goods as $k => $v) {
- $goods_id[] = $v['goods_id'];
- $num[] = $v['num'];
- $sku_id[] = -1;
- }
- } else {
- $goods_id = Dever::input('goods_id');
- if (!$goods_id) {
- Dever::alert('请传入商品');
- }
- $goods_id = explode(',', $goods_id);
- $sku_id = Dever::input('price_id');
- if ($sku_id) {
- $sku_id = explode(',', $sku_id);
- }
- $single_id = Dever::input('single_id');
- if ($single_id) {
- $single_id = explode(',', $single_id);
- }
- $input_id = Dever::input('input_id');
- if ($input_id) {
- $input_id = explode(',', $input_id);
- }
- $input_value = Dever::input('input_value');
- if ($input_value) {
- $input_value = explode(',', $input_value);
- }
-
- $num = Dever::input('num');
- if (!$num) {
- Dever::alert('请传入商品数量');
- }
- $num = explode(',', $num);
- }
-
- $data['wallet_cash'] = 0;
-
- $data['ps_cash'] = 0;
-
- $data['oprice'] = 0;
-
- $data['price'] = 0;
- $data['num'] = 0;
- $data['name'] = array();
- $count = count($goods_id);
-
- foreach ($goods_id as $k => $v) {
- $s = isset($sku_id[$k]) ? $sku_id[$k] : -1;
- $n = isset($num[$k]) ? $num[$k] : 1;
- $data['list'][$k] = Dever::load('goods/lib/info')->getPayInfo($v, $s);
- $w = array();
- $w['goods_id'] = $v;
- $w['sku_id'] = $s;
- $w['shop_id'] = $data['shop']['id'];
- $goods_sku = Dever::db('shop/goods_sku')->find($w);
- if ($goods_sku && isset($goods_sku['min'])) {
- $data['list'][$k]['min'] = $goods_sku['min'];
- }
- $data['list'][$k]['num'] = $n;
-
- $data['list'][$k]['ku_state'] = 1;
-
- $total = Dever::load('shop/lib/info')->checkTotal($n, $v, $data['shop']['id'], $s);
- if (isset($data['list'][$k]['min']) && $data['list'][$k]['min'] > 0) {
- if ($total < $data['list'][$k]['min']) {
- $total = 0;
- }
- }
- if ($total <= 0) {
- $data['list'][$k]['ku_state'] = 2;
- $data['list'][$k]['buy_num'] = 0;
- }
- if ($data['list'][$k]['ku_state'] == 1) {
- $data['list'][$k]['buy_num'] = $n;
- $data['num'] += $n;
- $data['price'] += $data['list'][$k]['price'] * $n;
- $data['name'][] = $data['list'][$k]['name'];
- }
- }
- $data['name'] = implode(',', $data['name']);
- if ($data['method'] == 2) {
- $data['ps_cash'] = $data['shop']['ps_cash'];
- if ($data['shop']['free_ps_cash'] && $data['shop']['free_ps_cash'] > 0 && $data['price'] >= $data['shop']['free_ps_cash']) {
- $data['ps_cash'] = 0;
- }
- }
- $data['oprice'] = $data['price'];
- return $data;
- }
-
- public function pay($method, $pay_method, $pay_type, $user, $shop, $name, $num, $goods, $oprice, $price, $cash, $address_id, $invoice_id, $info, $card, $wallet_cash, $coupon_id, $user_coupon_id, $coupon_cash, $cart = false, $system_source = 5, $refer = '')
- {
- if (!$user) {
- Dever::alert('错误的用户信息');
- }
- $uid = $user['id'];
- if ($uid > 0) {
- $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => 1));
- if (!$wechat) {
-
- }
- }
- if ($method == 2) {
- $ps_cash = $shop['ps_cash'];
- if ($shop['free_ps_cash'] && $shop['free_ps_cash'] > 0 && $price >= $shop['free_ps_cash']) {
- $ps_cash = 0;
- }
- $order_data['ps_cash'] = $ps_cash;
- $price += $order_data['ps_cash'];
- }
-
- $order_data['shop_id'] = $shop['id'];
- if ($shop['type'] == 10) {
- $order_data['shop_type'] = 2;
- } else {
- $order_data['shop_type'] = 1;
- }
-
- $order_data['area'] = $shop['area'] . ',' . $shop['id'];
- $order_data['uid'] = $uid;
- $order_data['mobile'] = $user['mobile'];
- $order_data['address_id'] = $address_id;
- $order_data['invoice_id'] = $invoice_id;
- $order_data['name'] = $name;
- $order_data['num'] = $num;
- $order_data['info'] = $info;
- $order_data['oprice'] = $oprice;
- $order_data['price'] = $price;
- $order_data['kou_cash'] = $cash;
- $order_data['method'] = $method;
- $order_data['pay_method'] = $pay_method;
- $order_data['pay_type'] = $pay_type;
- $order_data['refund_cash'] = 0;
- if ($card) {
- $order_data['card_code_id'] = $card['id'];
- $order_data['card_code_card'] = $card['card'];
- $order_data['card_code_cash'] = $card['cash'];
- } elseif ($wallet_cash) {
- $order_data['wallet_cash'] = $wallet_cash;
- }
- if ($user_coupon_id) {
- $order_data['user_coupon_id'] = $user_coupon_id;
- }
- if ($coupon_id) {
- $order_data['coupon_id'] = $coupon_id;
- }
- if ($coupon_cash) {
- $order_data['coupon_cash'] = $coupon_cash;
- }
- $order_data['order_num'] = $this->getOrderId();
- $id = Dever::db('shop/sell_order')->insert($order_data);
- if (!$id) {
- Dever::alert('支付失败');
- }
- foreach($goods as $k => $v) {
- if ($v['ku_state'] == 1) {
- $data['uid'] = $uid;
- $data['order_id'] = $id;
- $data['shop_id'] = $shop['id'];
- $data['goods_id'] = $v['id'];
- $data['sku_id'] = $v['sku_id'];
- $data['price'] = $v['price'];
- $data['num'] = $v['buy_num'];
- if (isset($v['user_coupon_id']) && $v['user_coupon_id']) {
- $data['user_coupon_id'] = $v['user_coupon_id'];
- }
- if (isset($v['coupon_id']) && $v['coupon_id']) {
- $data['coupon_id'] = $v['coupon_id'];
- }
- if (isset($v['coupon_cash']) && $v['coupon_cash']) {
- $data['coupon_cash'] = $v['coupon_cash'];
- } else {
- $data['coupon_cash'] = 0;
- }
- Dever::db('shop/sell_order_goods')->insert($data);
- }
- }
-
- $order_data['id'] = $id;
- $this->updateSell($order_data);
- if ($price <= 0 || $pay_type == 2) {
- $param['pay_product_id'] = $id;
- $param['pay_order_id'] = $order_data['order_num'];
- $param['pay_status'] = 2;
- $param['pay_cash'] = $price;
- $param['pay_msg'] = '';
- $this->success($param);
- if ($cart) {
-
- $this->dropCart($cart, $uid, $goods, $shop['id']);
- }
-
- $this->useCoupon($coupon_id, $user_coupon_id, $card, $wallet_cash);
-
- return array
- (
- 'order' => '',
- 'order_num' => $order_data['order_num'],
- 'order_id' => $id,
- 'type' => 'pay',
- );
- }
- $sell_config = Dever::db('main/sell_config')->one();
-
- $other = false;
- if (isset($shop['mid']) && $shop['mid']) {
- $other = array
- (
- 'mid' => $shop['mid'],
- 'order_id' => $order_data['order_num'] . '_' . $shop['id'],
- 'per' => $sell_config['per'],
- 'oprice' => $oprice,
- );
- }
- $param = array
- (
- 'project_id' => 1,
- 'channel_id' => 1,
- 'system_source' => $system_source,
- 'uid' => $uid,
- 'name' => $order_data['name'],
- 'cash' => $price,
- 'product_id' => $id,
- 'order_id' => $order_data['order_num'],
- 'other' => $other,
- 'refer' => $refer,
- );
- if ($uid > 0 && isset($wechat) && $wechat) {
- $param['openid'] = $wechat['openid'];
- }
- $receipt = Dever::input('receipt');
- if ($receipt) {
- $param['receipt'] = $receipt;
- }
- $result = Dever::load('pay/api.pay', $param);
-
-
- if ($cart) {
-
- $this->dropCart($cart, $uid, $goods, $shop['id']);
- }
-
- $this->useCoupon($coupon_id, $user_coupon_id, $card, $wallet_cash);
- $result['order_num'] = $order_data['order_num'];
- $result['order_id'] = $id;
- return $result;
- }
- public function dropCart($cart, $uid, $goods, $shop_id)
- {
- $where['uid'] = $uid;
- $where['shop_id'] = $shop_id;
- foreach ($goods as $k => $v) {
- $where['goods_id'] = $v['id'];
- if ($cart == 1) {
- Dever::db('shop/cart')->delete($where);
- } else {
- unset($where['uid']);
- Dever::db('shop/shop_cart')->delete($where);
- }
- }
- }
- public function useCoupon($coupon_id, $user_coupon_id, $card, $wallet_cash)
- {
- if ($user_coupon_id) {
- Dever::db('shop/user_coupon')->update(array('where_id' => $user_coupon_id, 'status' => 2));
- }
- if ($card) {
- $state = Dever::db('card/code')->incUseCash(array('where_id' => $card['id'], 'set_use_cash' => $card['cash']));
- } elseif ($wallet_cash) {
- }
-
- }
-
- public function rpay($id, $system_source = 5, $refer = '')
- {
- $order = Dever::db('shop/sell_order')->find($id);
- if (!$order) {
- Dever::alert('订单信息错误');
- }
- if ($order['status'] > 1) {
- Dever::alert('订单已支付或已取消');
- }
- $param = array
- (
- 'project_id' => 1,
- 'channel_id' => 1,
- 'system_source' => $system_source,
- 'uid' => $order['uid'],
- 'name' => $order['name'],
- 'cash' => $order['price'],
- 'product_id' => $id,
- 'order_id' => $order['order_num'],
- 'refer' => $refer,
- );
- $receipt = Dever::input('receipt');
- if ($receipt) {
- $param['receipt'] = $receipt;
- }
- $order = $this->getInfo($order);
- $result = Dever::load('pay/api.pay', $param);
- $result['order_time'] = $order['time'];
- $result['order_price'] = $order['price'];
- $result['order_num'] = $order['order_num'];
- $result['order_id'] = $id;
- return $result;
- }
-
- public function cpay($id, $system_source = 5, $refer = '')
- {
- $order = Dever::db('shop/sell_order')->find($id);
- if (!$order) {
- Dever::alert('订单信息错误');
- }
- $result['order_num'] = $order['order_num'];
- $result['order_id'] = $id;
- if ($order['status'] > 1 && $order['status'] <= 6) {
-
- $result['status'] = 1;
- } else {
-
- $result['status'] = 2;
- }
- return $result;
- }
-
- public function success_secure_api_token()
- {
- $project_id = Dever::input('pay_project_id');
- $info = Dever::db('pay/project')->one($project_id);
- if ($info) {
- return $info['key'];
- }
- return 'shop_dever_2020';
- }
-
- public function success_secure_api($param = array())
- {
- $this->success($param);
- }
-
- public function success($param = array())
- {
- $send = $param ? $param : Dever::preInput('pay_');
- $product_id = $send['pay_product_id'];
- $order_id = $send['pay_order_id'];
- $status = $send['pay_status'];
- $cash = $send['pay_cash'];
- $msg = $send['pay_msg'];
- $order = Dever::db('shop/sell_order')->one(array('id' => $product_id, 'time' => time()));
- if ($order && $order['status'] == 1) {
- $update = array();
- if ($status == 2) {
-
- $update['code'] = $this->getCode();
- if ($order['method'] == 1) {
- $msg = '您有一件自提商品已订购成功,取件码:' . $update['code'];
- } else {
- $msg = '您有一件外送商品已订购成功,核销码:' . $update['code'];
-
-
- }
-
- if (Dever::project('message') && $order['uid']) {
- $shop = Dever::db('shop/info')->one($order['shop_id']);
- $msg_param['type'] = 1;
- $msg_param['id'] = $order['id'];
- $msg_param['name'] = $shop['name'];
- $msg_param = Dever::json_encode($msg_param);
- Dever::project('message') && Dever::load('message/lib/data')->push(-1, $order['uid'], '订购成功通知', $msg, 2, 1, false, $msg_param);
- }
-
- if ($order['pay_method'] == 2) {
- if ($order['refund_cash'] > 0) {
- $status = 6;
- } else {
- $status = 5;
- }
- $update['fdate'] = time();
- }
- $update['status'] = $status;
- $update['where_id'] = $order['id'];
- $update['paydate'] = time();
- Dever::db('shop/sell_order')->update($update);
- }
- }
- return 'ok';
- }
-
- public function updatePs($order, $status = 1, $service_id = -1, $order_num = '')
- {
- $where['order_id'] = $order['id'];
- $where['clear'] = true;
- $data = Dever::db('shop/sell_order_ps')->find($where);
- $service = array();
- if ($service_id) {
- $service['service_id'] = $service_id;
- }
- if ($order_num) {
- $service['order_num'] = $order_num;
- }
- if (!$data) {
- $insert = $where;
- if ($service) {
- $insert['service'][] = $service;
- $insert['service'] = Dever::array_encode($insert['service']);
- }
- $insert['status'] = $status;
- if ($status == 2) {
- $insert['qu_date'] = time();
- }
-
- Dever::db('shop/sell_order_ps')->insert($insert);
- } else {
- $update = $where;
- $update['where_id'] = $data['id'];
- $update['status'] = $status;
- if ($status == 2) {
- $update['qu_date'] = time();
- }
- if ($status == 3) {
- $update['qs_date'] = time();
- }
- if ($service) {
- $data['service'] = Dever::array_decode($data['service']);
- $update['service'] = $data['service'];
- $update['service'][] = $service;
- $insert['service'] = Dever::array_encode($update['service']);
- }
- Dever::db('shop/sell_order_ps')->update($update);
- }
- }
-
- public function updateSell($order, $type = 1)
- {
- $where['order_id'] = $order['id'];
- $where['status'] = 1;
- $data = Dever::db('shop/sell_order_goods')->select($where);
- if ($data) {
- Dever::load('shop/lib/goods')->oper($order, $type, 2, $data);
- }
- }
-
- public function finish($info, $shop_id)
- {
- if ($info && $info['shop_id'] == $shop_id && $info['status'] <= 4) {
- if ($info['refund_cash'] > 0) {
- $status = 6;
- } else {
- $status = 5;
- }
- $state = Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => $status, 'fdate' => time()));
-
- if ($info['uid'] && $info['uid'] > 0) {
- $shop = Dever::db('shop/info')->one($info['shop_id']);
- $msg_param['type'] = 1;
- $msg_param['id'] = $info['id'];
- $msg_param['name'] = $shop['name'];
- $msg_param = Dever::json_encode($msg_param);
- $msg = '您有一笔订单已签收,祝您用餐愉快~';
- Dever::project('message') && Dever::project('message') && Dever::load('message/lib/data')->push(-1, $info['uid'], '订单完成通知', $msg, 1, 1, false, $msg_param);
- }
- if ($info['method'] == 2) {
- Dever::load('shop/lib/sell')->updatePs($info, 3);
- }
- if ($info['pay_method'] == 3 && $info['card_code_id']) {
-
- $card_update['where_id'] = $info['card_code_id'];
- $card_update['status'] = 4;
- Dever::db('goods/card_code')->update($card_update);
- }
- if ($info['shop_type'] == 2) {
- $w['parent_type'] = 2;
- $w['parent_order_id'] = $info['id'];
- $w['status'] = 4;
- $buy_order = Dever::db('shop/buy_order')->select($w);
- if ($buy_order) {
- foreach ($buy_order as $k => $v) {
- Dever::load('mshop/lib/buy')->set(1,1)->finish($shop_id, $v['id']);
- }
- }
- }
- return 'ok';
- } else {
- Dever::alert('您没有权限核销');
- }
- }
-
- public function yes_api()
- {
- $shop_id = Dever::input('shop_id');
- $order_id = Dever::input('order_id');
- $info = Dever::db('shop/sell_order')->find(array('id' => $order_id));
- if ($info && $info['type'] == 10) {
- $this->finish($info, $shop_id);
- } else {
- Dever::alert('您没有权限核销');
- }
- return 'reload';
- }
-
- public function getCode()
- {
- $where['code'] = Dever::rand(6, 0);
- $state = Dever::db('shop/sell_order')->one($where);
- if (!$state) {
- return $where['code'];
- } else {
- return $this->getCode();
- }
- }
-
- public function getOrderId()
- {
- $where['order_num'] = Dever::order('G');
- $state = Dever::db('shop/sell_order')->one($where);
- if (!$state) {
- return $where['order_num'];
- } else {
- return $this->getOrderId();
- }
- }
-
- public function show()
- {
- $id = Dever::input('order_id');
- $config = Dever::db('shop/sell_order')->config;
- $info = Dever::db('shop/sell_order')->one($id);
- $tk_status = Dever::db('shop/sell_order_refund')->config['status'];
- $tk_process = Dever::db('shop/sell_order_refund')->config['process'];
- $status = $config['status_manage'][$info['status']];
- $tk = Dever::db('shop/sell_order_refund')->find(array('order_id' => $info['id'], 'type' => 1));
- $shop = Dever::db('shop/info')->find($info['shop_id']);
- $user = Dever::db('passport/user')->find($info['uid']);
- $cdate = date('Y-m-d H:i', $info['cdate']);
- if ($info['operdate']) {
- $opertime = date('Y-m-d H:i', $info['operdate']);
- } else {
- $opertime = '';
- }
- if ($info['fdate']) {
- $fdate = date('Y-m-d H:i', $info['fdate']);
- } else {
- $fdate = '';
- }
- if (!$user) {
- $user['username'] = '无';
- }
- if (!isset($user['truename'])) {
- $user['truename'] = $user['username'];
- }
- if (!$info['coupon_cash']) {
- $info['coupon_cash'] = 0;
- }
- if (!$info['kou_cash']) {
- $info['kou_cash'] = 0;
- }
- if (!$info['ps_cash']) {
- $info['ps_cash'] = 0;
- }
- if (!$info['wallet_cash']) {
- $info['wallet_cash'] = 0;
- }
- if (!$info['card_code_cash']) {
- $info['card_code_cash'] = 0;
- }
- if ($info['card_code_card']) {
- $info['card_code_cash'] .= '('.$info['card_code_card'].')';
- }
- if ($tk && $tk['process'] == 1) {
- $status = '申请' . $tk_status[$tk['status']];
- $process = $tk_process[$tk['process']];
- $process = '';
- }
- $time = array();
- $time[] = array('下单时间', $cdate);
- if ($opertime) {
- if ($info['status'] == 2) {
- $time[] = array('通知时间', $opertime);
- }
- if ($info['status'] == 7) {
- $time[] = array('取消时间:', $opertime);
- }
- }
- if ($fdate) {
- $time[] = array('完成时间:', $fdate);
- }
- $result = array();
- $result[$info['order_num']] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('订单状态', $status),
- array('支付方式', $config['pay_method'][$info['pay_method']]),
- array('配送方式', $config['method'][$info['method']]),
- ),
-
- array
- (
- array('门店名称', $shop['name']),
- array('联系人', $shop['truename']),
- array('联系电话', $shop['mobile']),
- ),
- array
- (
- array('下单用户', $user['username']),
- array('联系电话', $info['mobile']),
- array('订单备注', $info['info']),
- ),
- array
- (
- array('支付金额', '¥ ' . round($info['price'], 2)),
- array('优惠券满减', '¥ ' . $info['coupon_cash']),
- array('配送费', '¥ ' . $info['ps_cash']),
- ),
- array
- (
- array('礼品卡抵扣', '¥ ' . round($info['card_code_cash'], 2)),
- array('钱包抵扣', '¥ ' . round($info['wallet_cash'], 2)),
- array('抹零', '¥ ' . round($info['kou_cash'], 2)),
- ),
- $time,
- )
- );
- if ($info['address_id'] > 0) {
- $address = Dever::load('passport/address')->getOne($info['uid'], $info['address_id']);
- if ($address) {
- $result['收货地址'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('联系人', $address['contact']),
- array('联系电话', $address['mobile']),
- ),
- array
- (
- array('收货地址', $address['address_info']),
- array('门牌号', $address['house_number']),
- ),
- ),
- );
- }
- }
-
- if ($info['invoice_id'] > 0) {
- $invoice = Dever::load('passport/invoice')->getOne($info['uid'], $info['invoice_id']);
- if ($invoice) {
- $result['发票信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('发票类型', $invoice['title_type_name']),
- array('抬头', $invoice['title']),
- array('税号', $invoice['number']),
- ),
- array
- (
- array('手机号', $invoice['mobile']),
- array('邮箱', $invoice['email']),
- ),
- ),
- );
- }
- }
- $info['ps_info'] = Dever::db('shop/sell_order_ps')->find(array('order_id' => $info['id']));
- if ($info['ps_info']) {
- $info['ps_info']['service'] = Dever::array_decode($info['ps_info']['service']);
- $info['ps_info']['cdate'] = date('Y-m-d H:i', $info['ps_info']['cdate']);
- if ($info['ps_info']['qs_date']) {
- $info['ps_info']['qs_date'] = date('Y-m-d H:i', $info['ps_info']['qs_date']);
- } else {
- $info['ps_info']['qs_date'] = '无';
- }
- $status = Dever::db('shop/sell_order_ps')->config['status'];
- $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
-
- $service = array();
- if ($info['ps_info']['service']) {
- foreach ($info['ps_info']['service'] as $k => $v) {
- if (isset($v['order_num']) && $v['order_num']) {
- $info['ps_info']['service'][$k]['service_name'] = '商家自送';
- if ($v['service_id'] > 0) {
- $service_info = Dever::db('shop/service')->find($v['service_id']);
- $info['ps_info']['service'][$k]['service_name'] = $service_info['name'];
- }
- $service[] = array
- (
- array('名称', $info['ps_info']['service'][$k]['service_name']),
- array('单号', isset($v['order_num']) ? $v['order_num'] : ''),
- );
- }
- }
- }
- $result['物流信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('发货时间', $info['ps_info']['cdate']),
- array('收货时间', $info['ps_info']['qs_date']),
- array('查单', '<a href="https://www.kuaidi100.com/?from=openv" target="_blank">点此手动查单</a>'),
- ),
- ),
- );
- $result['物流信息']['content'] = array_merge($result['物流信息']['content'], $service);
- }
- if (!$info['refund_cash']) {
- $info['refund_cash'] = 0;
- }
- if ($info['refund_cash'] > 0 && $tk) {
- $process = $tk_process[$tk['process']];
- $tk['cdate'] = date('Y-m-d H:i', $tk['cdate']);
- $result['退款信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('退款金额', $info['refund_cash']),
- array('数量', $info['num']),
- array('退款进度', $process),
- ),
- array
- (
- array('申请时间', $tk['cdate']),
- array('退款原因', $tk['desc']),
- ),
- ),
- );
- }
- $body = $refund_body = array();
- $body_total = array();
- $body_total['price'] = 0;
- $body_total['num'] = 0;
- $refund_body_total = array();
- $refund_body_total['price'] = 0;
- $refund_body_total['num'] = 0;
- $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
- $goods_status = Dever::db('shop/sell_order_goods')->config['status'];
- foreach ($goods as $k => $v) {
- $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
- $status = $goods_status[$v['status']];
- $tk = Dever::db('shop/sell_order_refund')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id'], 'type' => 2));
- if ($tk && $tk['process'] == 1) {
- $status = '申请' . $tk_status[$tk['status']];
-
- }
- if (isset($goods_info['sku'])) {
- $sku = $goods_info['sku']['string'];
- } else {
- $sku = '无';
- }
- if ($info['shop_type'] == 2 && $info['status'] > 1 && $info['status'] < 7) {
- $tui = Dever::url('buy_order_tui?shop_id='.$v['shop_id'].'&order_goods_id=' . $v['id'] . '&order_id=' . $info['id'] . '&cash=' . $v['price'], 'shop');
- $status = '<a href="javascript:;" onclick="fastEdit($(this), \''.$tui.'\', \'退款\', \'\', 1)" class="layui-btn">退款</a>';
- }
- $d = array
- (
- 'pic' => $goods_info['cover'],
- 'name' => $goods_info['name'],
- 'sku' => $sku,
- 'price' => $v['price'],
- 'num' => $v['num'],
- 'status' => $status,
- );
- if ($goods_info['price_type'] > 2) {
- $d['goods'] = $goods_info['goods'];
- }
- if ($tk && $v['status'] == 3) {
- $d['status'] = $tk_status[$tk['status']];
- $refund_body[] = $d;
- $price = $v['price']*$v['num'];
- $refund_body_total['price'] += $price;
- $refund_body_total['num'] += $v['num'];
- } else {
- $body[] = $d;
- $price = $v['price']*$v['num'];
- $body_total['price'] += $price;
- $body_total['num'] += $v['num'];
- }
- }
- if ($body) {
- if ($refund_body_total['price']) {
- $body_total['set_price'] = $body_total['price'] - $refund_body_total['price'];
- }
- if ($refund_body_total['num']) {
- $body_total['set_num'] = $body_total['num'] - $refund_body_total['num'];
- }
- $result['商品清单'] = array
- (
- 'type' => 'list',
- 'content' => $body,
- 'total' => $body_total,
- );
- }
- if ($refund_body) {
- $result['退款商品'] = array
- (
- 'type' => 'list',
- 'content' => $refund_body,
- 'total' => $refund_body_total,
- );
- }
- $search_option_shop_type = Dever::input('search_option_shop_type');
- if ($search_option_shop_type == 2) {
-
- $buy_order = Dever::db('shop/buy_order')->getDataToId(array('type' => 1, 'type_id' => $info['shop_id'], 'parent_type' => 2, 'parent_order_id' => $info['id']));
- $source_order_id = array();
- if ($buy_order) {
- $source_order_id = array_keys($buy_order);
- }
-
- if ($source_order_id) {
- $cash_order = Dever::db('cash/order')->getDataByOrderId(array('source_order_id' => $source_order_id));
- $col = 'cash';
- }
- }
- if (isset($cash_order) && $cash_order) {
- $head = array('序号', '结算单号', '数量', '金额', '结算类型', '入账状态', '审核状态', '结算时间', '审核备注', '管理');
- $body = array();
- $config = Dever::db('cash/order')->config;
- foreach ($cash_order as $k => $v) {
- $cdate = date('Y-m-d H:i', $v['cdate']);
- $fdate = $v['fdate'] ? date('Y-m-d H:i', $v['fdate']) : '';
- $operdate = $v['operdate'] ? date('Y-m-d H:i', $v['operdate']) : '';
- $cash = $v[$col];
- $url = Dever::url('project/database/list?project=shop&table=buy_order_goods&order_id='.$v['source_order_id'].'&page_type=1', 'manage');
- $v['source_order_num'] = '<a href="'.$url.'" style="color:blue">'.$v['source_order_num'].'</a>';
- $m = '';
- if ($v['audit'] == 1 && $v['audit_type'] == 2) {
- $url = Dever::url('project/database/update?project=cash&table=order&where_id='.$v['id'].'&col=audit,desc', 'manage');
- $m = '<a href="javascript:;" onclick="fastEdit($(this), \''.$url.'\', \'审核\', \'\', 1)" class="layui-btn">审核</a>';
- }
- $d = array
- (
- $k+1,
- $v['order_num'],
- $v['num'],
- $cash,
- $config['config_jstype'][$v['jstype']],
- $config['config_status'][$v['status']],
- $config['config_audit'][$v['audit']],
- $operdate,
- $v['desc'],
- $m,
- );
- $body[] = $d;
- }
- $result['对账清单'] = array
- (
- 'type' => 'table',
- 'content' => array
- (
- 'head' => $head,
- 'body' => $body,
- )
- );
-
- }
-
- $head = array
- (
- 'name' => '基本信息',
- 'btn' => array(),
- );
- $html = Dever::show($head, $result);
- return $html;
- }
-
- public function tixian()
- {
- $param = array();
- ksort($param);
- $string = array();
- foreach ($param as $k => $v) {
- if (strstr($v, '&') || strstr($v, '@')) {
- $v = urlencode($v);
- }
- $string[] = $k . '=' . $v;
- }
- }
-
-
- public function notice($info)
- {
- $config = Dever::db('shop/sell_order')->config;
- $state = Dever::db('shop/sell_order')->update(array('where_id' => $info['id'], 'status' => 3, 'operdate' => time()));
-
- if ($info['uid'] && $info['uid'] > 0) {
- $shop = Dever::db('shop/info')->one($info['shop_id']);
- $msg_param['type'] = 1;
- $msg_param['id'] = $info['id'];
- $msg_param['name'] = $shop['name'];
- $msg_param = Dever::json_encode($msg_param);
- if ($info['method'] == 1) {
- $msg = '您有一件自提商品已完成配货,请尽快到指定门店使用取件码取货,取件码:' . $info['code'];
- $name = '取货通知';
- $wechat_msg = '您的商品已完成配货';
- } else {
- $msg = '您有一件外送商品已开始配送,收货时请将取件码提供给配送员核实货品信息,取件码:' . $info['code'];
- $name = '配送通知';
- $wechat_msg = '您的商品已开始配送';
- }
-
- Dever::project('message') && Dever::load('message/lib/data')->push(-1, $info['uid'], $name, $msg, 1, 1, false, $msg_param);
- if (Dever::project('wechat_applet')) {
- $user = Dever::db('passport/wechat')->one(array('uid' => $info['uid'], 'system_id' => 1, 'system_source' => 5));
- if ($user && $user['openid']) {
- $info['status_name'] = $config['status'][$info['status']];
- $send = array
- (
- 'character_string6' => array
- (
- 'value' => $info['order_num'],
- ),
-
- 'phrase7' => array
- (
- 'value' => $info['status_name'],
- ),
- 'thing8' => array
- (
- 'value' => $info['code'],
- ),
- 'amount1' => array
- (
- 'value' => $info['price'] . '元',
- ),
- 'thing5' => array
- (
- 'value' => $wechat_msg,
- ),
- );
- $send = Dever::json_encode($send);
- Dever::load('wechat_applet/subscribe')->sendOne('order_process', 1, $user['openid'], 'pages/app/order/order?id=' . $info['id'], $send, Dever::config('base')->wechat_applet);
- }
- }
- }
- }
-
- public function audit_commit()
- {
- $order_id = Dever::input('order_id');
- $order = Dever::db('shop/sell_order')->find($order_id);
- if (!$order || ($order && $order['status'] != 2)) {
- Dever::alert('当前订单状态无法拆单');
- }
- if ($order['shop_type'] != 2) {
- Dever::alert('这不是平台店的订单');
- }
- $order['type'] = 2;
- $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $order_id));
- $shop = Dever::db('shop/info')->find($order['shop_id']);
- $data = Dever::load('mshop/lib/buy')->assign($goods, $order, $shop);
- $send = array();
- if (!$goods && $data) {
-
- $i = $order['order_index'];
- foreach ($data as $k => $v) {
- foreach ($v as $k1 => $v1) {
- $v1['order_num'] .= '_' . $i;
- $state = Dever::load('mshop/lib/buy')->createOrder($v1);
- $send[$state] = $v1;
- }
- $i++;
- }
- Dever::db('shop/sell_order')->update(array('where_id' => $order['id'], 'status' => 3));
- } else {
- Dever::db('shop/sell_order')->update(array('where_id' => $order['id'], 'audit' => 1));
- if ($goods) {
- $string = array();
- foreach ($goods as $k => $v) {
- $info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
-
- if ($info['sku_name']) {
- $info['name'] .= '('.$info['sku_name'].')';
- }
- $string[] = $info['name'];
- }
- $string = implode('、', $string);
- Dever::alert('商品:'.$string.'库存不足或厂家未生产,请联系供货商备货,该订单进入重新审核状态');
- } else {
- Dever::alert('供货商库存不足,请联系供货商备货,该订单进入重新审核状态');
- }
- }
- if ($send) {
- foreach ($send as $k => $v) {
- Dever::load('mshop/lib/buy')->sendMsg($v['source_type'], $v['source_id'], $k);
- $order_info = Dever::db('shop/buy_order')->find(array('id' => $k, 'clear' => true));
- Dever::load('cash/lib/order')->up($order_info, 1, 1);
- }
- }
- return 'ok';
- }
- }
|