123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578 |
- <?php
- namespace Mshop\Lib;
- use Dever;
- class Buy
- {
-
- public $type = 1;
-
- public $view = 1;
-
- public $config = array();
-
- public $table = 'shop/buy_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 > 10) {
- $type = $this->type - 10;
- $where['source_type'] = $type;
- $where['source_id'] = $id;
- } else {
- $where['type'] = $this->type;
- $where['type_id'] = $id;
- }
-
- if (!$where) {
- Dever::alert('参数错误');
- }
- return $where;
- }
-
- public function getList($id)
- {
- $result = array();
- $where = $this->where($id);
- $status = Dever::input('status');
- if ($status) {
- if ($status == 'refund') {
- $where['refund_status'] = 2;
- } else {
- $where['status'] = $status;
- }
- }
- $order_num = Dever::input('order_num');
- if ($order_num) {
- $where['order_num'] = $order_num;
- }
- $refund_status = Dever::input('refund_status');
- if ($refund_status) {
- $where['refund_status'] = $refund_status;
- }
- $result['search_value'] = $where;
- $result['search_value']['day'] = $day = Dever::input('day');
- if ($day) {
- if ($this->type > 10) {
- $where['start_o'] = Dever::maketime($day . ' 00:00:00');
- $where['end_o'] = Dever::maketime($day . ' 23:59:59');
- } elseif ($this->type == 2) {
- $where['start_f'] = Dever::maketime($day . ' 00:00:00');
- $where['end_f'] = Dever::maketime($day . ' 23:59:59');
- } else {
- $where['start'] = Dever::maketime($day . ' 00:00:00');
- $where['end'] = Dever::maketime($day . ' 23:59:59');
- }
- }
- $result['search_value']['start'] = $start = Dever::input('start');
- $result['search_value']['end'] = $end = Dever::input('end');
- if ($start && $end) {
- if ($this->type > 10) {
- $where['start_o'] = Dever::maketime($start);
- $where['end_o'] = Dever::maketime($end);
- } elseif ($this->type == 2) {
- $where['start_f'] = Dever::maketime($start);
- $where['end_f'] = Dever::maketime($end);
- } else {
- $where['start'] = Dever::maketime($start);
- $where['end'] = Dever::maketime($end);
- }
- }
- $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' => '待审核'),
- array('value' => 3, 'name' => '待发货'),
- array('value' => 4, 'name' => '待收货确认'),
- array('value' => 5, 'name' => '已完成'),
- array('value' => 6, 'name' => '已完成(有退款)'),
- array('value' => '7,8,11', 'name' => '已取消'),
- );
- $result['config'] = Dever::db('main/manage_config')->find();
- 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, true);
- }
- $result['config'] = Dever::db('main/manage_config')->find();
- return $result;
- }
-
- public function getRefund($id, $order_id)
- {
- $data = $this->getView($id, $order_id, false);
- $data['refund'] = Dever::db('shop/buy_order_refund')->select(array('order_id' => $info['id']));
- return $data;
- }
-
- public function getInfo($info, $view = false)
- {
- 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['goods'] = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
- if ($info['type'] == 1) {
- $info['type_info'] = Dever::db('shop/info')->getOne($info['type_id']);
- } elseif ($info['type'] == 2) {
- $info['type_info'] = Dever::db('store/info')->find($info['type_id']);
- } elseif ($info['type'] == 3) {
- $info['type_info'] = Dever::db('factory/info')->find($info['type_id']);
- }
- if ($info['source_type'] == 1) {
- $info['source_info'] = Dever::db('shop/info')->getOne($info['source_id']);
- } elseif ($info['source_type'] == 2) {
- $info['source_info'] = Dever::db('store/info')->find($info['source_id']);
- } elseif ($info['source_type'] == 3) {
- $info['source_info'] = Dever::db('factory/info')->find($info['source_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'] = $info['cdate'];
- }
- $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
- $goods_process = Dever::db('shop/buy_order_refund')->config['process'];
- if ($view || $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']];
- }
- } 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']];
- }
- }
- if (!$info['refund_cash']) {
- $info['refund_cash'] = 0;
- }
-
- $info['ps_info'] = Dever::db('shop/buy_order_ps')->find(array('order_id' => $info['id']));
- if ($info['ps_info']) {
- $info['ps_info']['service_name'] = '商家自送';
- $info['ps_info']['cdate'] = date('Y-m-d H:i', $info['ps_info']['cdate']);
- if ($info['ps_info']['ydate']) {
- $info['ps_info']['ydate'] = date('Y-m-d H:i', $info['ps_info']['ydate']);
- }
- $status = Dever::db('shop/buy_order_ps')->config['status'];
- $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
-
- if ($info['ps_info']['service_id'] > 0) {
-
- $service = Dever::db('shop/service')->find($info['ps_info']['service_id']);
- $info['ps_info']['service_name'] = $service['name'];
- }
- }
- return $info;
- }
-
- public function action($type, $type_id, $name, $num, $goods, $price, $info, $refer = '')
- {
- $order_data['type'] = $type;
- $order_data['type_id'] = $type_id;
- $order_data['name'] = $name;
- $order_data['num'] = $num;
- $order_data['info'] = $info;
- $order_data['price'] = $price;
- $order_data['order_num'] = $this->getOrderId();
- $order_data['refund_cash'] = 0;
- $order_data['refund_p_cash'] = 0;
- $id = Dever::db('shop/buy_order')->insert($order_data);
- if (!$id) {
- Dever::alert('支付失败');
- }
- foreach($goods as $k => $v) {
- $data['order_id'] = $id;
- $data['goods_id'] = $v['id'];
- $data['sku_id'] = $v['sku_id'];
- $data['price'] = $v['price'];
- $data['num'] = $v['buy_num'];
- Dever::db('shop/buy_order_goods')->insert($data);
- }
- if ($price <= 0) {
- $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);
- return array
- (
- 'order' => '',
- 'order_num' => $order_data['order_num'],
- 'order_id' => $id,
- 'type' => 'pay',
- );
- }
- $param = array
- (
- 'project_id' => 2,
- 'channel_id' => 1,
- 'system_source' => 5,
- 'uid' => -1,
- 'name' => $order_data['name'],
- 'cash' => $price,
- 'product_id' => $id,
- 'order_id' => $order_data['order_num'],
- 'refer' => $refer,
- );
- $receipt = Dever::input('receipt');
- if ($receipt) {
- $param['receipt'] = $receipt;
- }
-
- $result['type'] = 'test';
- $result['order'] = '';
- $result['order_num'] = $order_data['order_num'];
- $result['order_id'] = $id;
- return $result;
- }
-
- public function raction($id, $refer = '')
- {
- $order = Dever::db('shop/buy_order')->find($id);
- if (!$order) {
- Dever::alert('订单信息错误');
- }
- if ($order['status'] > 1) {
- Dever::alert('订单已支付或已取消');
- }
- $param = array
- (
- 'project_id' => 2,
- 'channel_id' => 1,
- 'system_source' => 5,
- 'uid' => -1,
- '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;
- }
- $result = Dever::load('pay/api.pay', $param);
- $result['order_num'] = $order['order_num'];
- $result['order_id'] = $id;
- 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_buy_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/buy_order')->one(array('id' => $product_id, 'time' => time()));
- if ($order && $order['status'] == 1 && $status == 2) {
- $update['status'] = 2;
- $update['where_id'] = $order['id'];
- Dever::db('shop/buy_order')->update($update);
-
- Dever::load('cash/lib/order')->up($order, 1, 1);
- }
- return 'ok';
- }
-
- public function getOrderId()
- {
- $where['order_num'] = Dever::order('C');
- $state = Dever::db('shop/buy_order')->one($where);
- if (!$state) {
- return $where['order_num'];
- } else {
- return $this->getOrderId();
- }
- }
-
- public function updatePs($order, $status = 1)
- {
- $where['order_id'] = $order['id'];
- $data = Dever::db('shop/buy_order_ps')->find($where);
- if ($data) {
- $update['where_id'] = $data['id'];
- $update['status'] = $status;
- $update['ydate'] = time();
- Dever::db('shop/buy_order_ps')->update($update);
- }
- }
-
- public function finish($id, $order_id)
- {
- $data = $this->getView($id, $order_id, false);
- if ($data['status'] <= 4) {
- if ($data['refund_cash'] > 0) {
- $status = 6;
- } else {
- $status = 5;
- }
- $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => $status, 'fdate' => time()));
- if ($state) {
- $this->updatePs($data, 3);
-
- $where['order_id'] = $data['id'];
- $where['status'] = 1;
- $goods = Dever::db('shop/buy_order_goods')->select($where);
- if ($goods) {
- Dever::load('shop/lib/goods')->oper($data, 1, 1, $goods);
- }
-
- Dever::load('cash/lib/order')->up($data, 1, 2);
- }
- return 'ok';
- } else {
- Dever::alert('您没有权限');
- }
- }
-
- public function cancel($id, $order_id)
- {
- $data = $this->getView($id, $order_id, false);
- if ($data['status'] == 1) {
- $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => 7, 'operdate' => time()));
-
- if ($state) {
-
- }
- return 'ok';
- } else {
- Dever::alert('当前订单状态不允许取消');
- }
- }
-
- public function orderStatus($id)
- {
- $config = Dever::db('shop/buy_order')->config;
- $info = Dever::db('shop/buy_order')->one($id);
- $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'process' => 1));
- $status = $config['status'][$info['status']];
- if ($tk) {
- $status = '申请退款中';
- }
- return $status;
- }
-
- public function refund_commit_api()
- {
- $id = Dever::input('id');
- $process = Dever::input('process');
- return Dever::load('shop/lib/refund')->set('buy')->action($id, $process, false);
- }
-
- public function refund_apply_commit_api()
- {
- $order_id = Dever::input('order_id');
- $type = Dever::input('type');
- $type_id = Dever::input('type_id');
- $desc = Dever::input('desc');
- $pic = Dever::input('pic');
- return Dever::load('shop/lib/refund')->set('buy')->apply($type, $type_id, $order_id, false, 3, 0, $desc, $pic, 2);
- }
-
- public function refund_apply_info_commit_api()
- {
- $order_id = Dever::input('order_id');
- $status = Dever::input('status');
- $desc = Dever::input('desc');
- $pic = Dever::input('pic');
- $type = Dever::input('type');
- $type_id = Dever::input('type_id');
- return Dever::load('shop/lib/refund')->set('buy')->apply($type, $type_id, $order_id, false, $status, 0, $desc, $pic, 1);
- }
-
- public function refund_apply_info_one_commit_api()
- {
- $order_id = Dever::input('order_id');
- $order_goods_id = Dever::input('order_goods_id');
- $num = Dever::input('num', 0);
- $status = Dever::input('status');
- $desc = Dever::input('desc');
- $pic = Dever::input('pic');
- $type = Dever::input('type');
- $type_id = Dever::input('type_id');
- return Dever::load('shop/lib/refund')->set('buy')->apply($type, $type_id, $order_id, $order_goods_id, $status, $num, $desc, $pic, 1);
- }
-
- public function show()
- {
- $id = Dever::input('order_id');
- $type = Dever::input('type', 1);
- $cash_type = Dever::input('cash', 1);
- $config = Dever::db('shop/buy_order')->config;
- $info = Dever::db('shop/buy_order')->one($id);
- $tk_status = Dever::db('shop/buy_order_refund')->config['status'];
- $tk_process = Dever::db('shop/buy_order_refund')->config['process'];
- $status = $config['status'][$info['status']];
- $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'type' => 1));
- $cdate = date('Y-m-d H:i', $info['cdate']);
- if ($info['operdate']) {
- $operdate = date('Y-m-d H:i', $info['operdate']);
- } else {
- $operdate = '';
- }
- if ($info['fdate']) {
- $fdate = date('Y-m-d H:i', $info['fdate']);
- } else {
- $fdate = '';
- }
-
-
- $html = '<div class="layui-col-md12"><div class="layui-card"><div class="layui-card-header">基本信息</div><div class="layui-card-body">';
- $html .= '<table class="layui-table"><thead><tr><th style="width:20%">项目</th><th style="width:80%">详情</th></tr> </thead><tbody>';
- if ($type == 2 || $info['type'] == 2) {
- $info['price'] = $info['p_price'];
- }
- if ($type == 3) {
- $html .= '<tr>
- <td>订单信息</td>
- <td>'.$this->table(false, array(array('订单号:' . $info['order_num'], '数量:' . $info['num'], '状态:' . $status))).'</td>
- </tr>';
- } else {
- $html .= '<tr>
- <td>订单信息</td>
- <td>'.$this->table(false, array(array('订单号:' . $info['order_num'], '金额:' . $info['price'], '数量:' . $info['num'], '状态:' . $status))).'</td>
- </tr>';
- }
-
- if ($type == 1 && $tk && $tk['process'] == 1) {
- $status = '申请' . $tk_status[$tk['status']];
- }
- if ($type == 1) {
- $time = array('下单时间:' . $cdate, '订货时间:' . $operdate);
- } else {
- $time = array('订货时间:' . $operdate);
- }
- if ($fdate) {
- $time[] = '完成时间:' . $fdate;
- }
-
- $html .= '<tr>
- <td>订单时间</td>
- <td>'.$this->table(false, array($time)).'</td>
- </tr>';
- if ($info['type'] == 1) {
- $type_info = Dever::db('shop/info')->find($info['type_id']);
- } elseif ($info['type'] == 2) {
- $type_info = Dever::db('store/info')->find($info['type_id']);
- } elseif ($info['type'] == 3) {
- $type_info = Dever::db('store/info')->find($info['type_id']);
- }
- $html .= '<tr>
- <td>配送信息</td>
- <td>'.$this->table(false, array(array($type_info['name'] . ',' . $type_info['truename'] . ',' . $type_info['mobile'] . ',' . $type_info['address']))).'</td>
- </tr>';
- if ($type == 1 && $info['source_id'] > 0) {
- if ($info['source_type'] == 2) {
-
- $source_info = Dever::db('store/info')->find($info['source_id']);
- } elseif ($info['source_type'] == 3) {
-
- $source_info = Dever::db('factory/info')->find($info['source_id']);
- }
- $html .= '<tr>
- <td>供应商信息</td>
- <td>'.$this->table(false, array(array($source_info['name'] . ',' . $source_info['truename'] . ',' . $source_info['mobile']))).'</td>
- </tr>';
- }
-
- if ($info['info']) {
- $html .= '<tr>
- <td>订单备注</td>
- <td>'.$this->table(false, array(array($info['info']))).'</td>
- </tr>';
- }
- if ($type == 2) {
- $config = Dever::load('factory/admin/auth.config');
- $button = array();
- if ($info['status'] < 5) {
- $print = Dever::url('admin/order.print?id=' . $info['id'] . '&type=1', 'factory');
- $button[] = '<a class="layui-btn layui-btn-primary" href="'.$print.'" target="_blank">打印货单</a>';
- }
- if ($info['status'] == 3) {
- $send = Dever::url('order_send?id=' . $info['id'], 'factory');
- $cancel = Dever::url('lib/buy.refund_apply_commit?json=1', 'mshop');
- $button[] = '<button class="layui-btn layui-btn-primary" onclick="fastEdit($(this), \''.$send.'\', \'配送发货\', \'\', 1)">配送发货</button>';
- $button[] = '<button class="layui-btn layui-btn-primary" onclick="cancel('.$info['id'].','.$info['source_id'].', \''.$cancel.'\')">取消订单</button>';
- }
- $config['phone'] = '您的专属客服:' . $config['kf_name'] . ',联系电话:' . $config['phone'];
- $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系平台</button>';
- $html .= '<tr>
- <td>功能按钮</td>
- <td>'.$this->table(false, array($button)).'</td>
- </tr>';
- } elseif ($type == 3) {
- $config = Dever::load('factory/admin/auth.config');
- $button = array();
- $print = Dever::url('admin/order.print?id=' . $info['id'] . '&type=2', 'store');
- $button[] = '<a class="layui-btn layui-btn-primary" href="'.$print.'" target="_blank">打印货单</a>';
- if ($info['status'] == 3) {
- $send = Dever::url('order_send?id=' . $info['id'] . '&type=2', 'store');
- $button[] = '<button class="layui-btn layui-btn-primary" onclick="fastEdit($(this), \''.$send.'\', \'配送发货\', \'\', 1)">配送发货</button>';
- }
- if ($info['status'] == 4 && $info['type'] == 2) {
- $url = Dever::url('admin/factory_order.action_commit?order_id='.$info['id'], 'store');
- $button[] = '<button class="layui-btn layui-btn-primary" onclick="load(\''.$url.'\')">确认收货</button>';
- }
- $config['phone'] = '您的专属客服:' . $config['kf_name'] . ',联系电话:' . $config['phone'];
- $button[] = '<button class="layui-btn layui-btn-primary" onclick="showAlert(\''.$config['phone'].'\')">联系平台</button>';
- $html .= '<tr>
- <td>功能按钮</td>
- <td>'.$this->table(false, array($button)).'</td>
- </tr>';
- }
- $html .= '</tbody></table></div></div>';
- $url = Dever::url('lib/buy.refund_commit?json=1', 'mshop');
- if (!$info['refund_cash']) {
- $info['refund_cash'] = 0;
- }
- if ($info['refund_cash'] > 0 && $tk) {
-
- if ($tk['process'] == 1) {
- $process = '<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
- } else {
- $process = $tk_process[$tk['process']];
- }
- $desc = array();
- $desc['退款原因'] = $tk['desc'];
- $desc['退款图片'] = '暂无';
- if ($tk['pic']) {
- $desc['退款图片'] = '';
- $pic = explode(',', $tk['pic']);
- foreach ($pic as $k => $v) {
- $desc['退款图片'] .= '<a href="'.$v.'" target="_blank"><img src="'.$v.'" width="100"/></a>';
- }
- }
- $tk['desc'] = '<a href="javascript:showAlert($(\'#desc_content\').html());">查看</a><span id="desc_content" style="display:none">'.Dever::table($desc).'</span>';
- $head = array('退款金额', '数量', '退款原因', '退款进度');
- $body = array(array($info['refund_cash'], $info['num'], $tk['desc'], $process));
- $html .= '<div class="layui-card"><div class="layui-card-header">退款信息</div><div class="layui-card-body">' . $this->table($head, $body) . '</div></div>';
- }
- $info['ps_info'] = Dever::db('shop/buy_order_ps')->find(array('order_id' => $info['id']));
- if ($info['ps_info']) {
- $info['ps_info']['service_name'] = '供应商自送';
- $info['ps_info']['cdate'] = date('Y-m-d H:i', $info['ps_info']['cdate']);
- if ($info['ps_info']['ydate']) {
- $info['ps_info']['ydate'] = date('Y-m-d H:i', $info['ps_info']['ydate']);
- } else {
- $info['ps_info']['ydate'] = '无';
- }
- $status = Dever::db('shop/buy_order_ps')->config['status'];
- $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
-
- if ($info['ps_info']['service_id'] > 0) {
-
- $service = Dever::db('shop/service')->find($info['ps_info']['service_id']);
- $info['ps_info']['service_name'] = $service['name'];
- }
- $info['ps_info']['order_num'] = str_replace("\r\n", ',', $info['ps_info']['order_num']);
- if ($type == 3) {
- $head = array('名称', '单号', '数量', '重量', '体积', '发货时间', '收货时间');
- $body = array(array($info['ps_info']['service_name'], $info['ps_info']['order_num'], $info['ps_info']['num'], $info['ps_info']['zl'], $info['ps_info']['tj'], $info['ps_info']['cdate'], $info['ps_info']['ydate']));
- } else {
- $head = array('名称', '单号', '费用', '数量', '重量', '体积', '配货员', '打包员', '发货时间', '收货时间');
- $body = array(array($info['ps_info']['service_name'], $info['ps_info']['order_num'], $info['ps_info']['price'], $info['ps_info']['num'], $info['ps_info']['zl'], $info['ps_info']['tj'], $info['ps_info']['phy'], $info['ps_info']['dby'], $info['ps_info']['cdate'], $info['ps_info']['ydate']));
- }
-
- $html .= '<div class="layui-card"><div class="layui-card-header">物流信息</div><div class="layui-card-body">' . $this->table($head, $body) . '</div></div>';
- }
-
- $body = array();
- $body_total = array();
- $body_total['price'] = 0;
- $body_total['num'] = 0;
- $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
- $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
- $refund_body = array();
- $refund_body_total = array();
- $refund_body_total['price'] = 0;
- $refund_body_total['num'] = 0;
- foreach ($goods as $k => $v) {
- if ($type == 2 || $info['type'] == 2) {
- $v['price'] = $v['p_price'];
- }
- $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
- $status = $goods_status[$v['status']];
- $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id'], 'type' => 2));
- if ($tk && $tk['process'] == 1) {
- if ($type == 1) {
- $status = '申请' . $tk_status[$tk['status']];
- } else {
- $status = '已上报';
- }
- if ($type == 1) {
- $desc = array();
- $desc['退款原因'] = $tk['desc'];
- $desc['退款图片'] = '暂无';
- if ($tk['pic']) {
- $desc['退款图片'] = '';
- $pic = explode(',', $tk['pic']);
- foreach ($pic as $k1 => $v1) {
- $desc['退款图片'] .= '<a href="'.$v1.'" target="_blank"><img src="'.$v1.'" width="100"/></a>';
- }
- }
- $status .= ' <a href="javascript:showAlert($(\'#desc_content\').html());">查看原因</a><span id="desc_content" style="display:none">'.Dever::table($desc).'</span>';
- $status .= ' <a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
- }
- } elseif ($type > 1 && (!$tk || ($tk && $tk['process'] == 3))) {
- $tui = Dever::url('lib/buy.refund_apply_info_one_commit?json=1', 'mshop');
- if ($info['status'] == 3) {
- $status = '<a href="javascript:;" onclick="tui('.$v['id'].','.$info['id'].','.$info['source_id'].', 2, \''.$tui.'\')" class="layui-btn">缺货退款</a>';
- } elseif ($info['status'] == 4) {
- $status = '<a href="javascript:;" onclick="tui('.$v['id'].','.$info['id'].','.$info['source_id'].', 1, \''.$tui.'\')" class="layui-btn">报损退款</a>';
- }
- }
- if (isset($goods_info['sku'])) {
- $sku = '[' . $goods_info['sku']['string'] . ']';
- } else {
- $sku = '';
- }
- if ($tk && $v['status'] == 3 && $tk['status'] != 3) {
- $d = array
- (
- $goods_info['name'] . ' ' . $sku,
- $v['price'],
- $v['num'],
- $tk_status[$tk['status']],
- );
- if ($type == 3) {
- unset($d[1]);
- }
- $refund_body[] = $d;
- $price = $v['price']*$v['num'];
- $refund_body_total['price'] += $price;
- $refund_body_total['num'] += $v['num'];
- } else {
- $d = array
- (
- $goods_info['name'] . ' ' . $sku,
- $v['price'],
- $v['num'],
- $status,
- );
- if ($type == 3) {
- unset($d[1]);
- }
- $body[] = $d;
- $price = $v['price']*$v['num'];
- $body_total['price'] += $price;
- $body_total['num'] += $v['num'];
- }
- }
- if ($body) {
- $head = array('名称', '单价', '数量', '状态');
- $d = array
- (
- '合计',
- round($body_total['price'], 2),
- $body_total['num'],
- '-'
- );
- if ($type == 3) {
- unset($head[1]);
- unset($d[1]);
- }
- $body[] = $d;
- $html .= '<div class="layui-card"><div class="layui-card-header">商品清单</div><div class="layui-card-body" style="max-heights: 500px;overflow: auto;">' . $this->table($head, $body) . '</div></div>';
- }
- if ($refund_body) {
- $head = array('名称', '单价', '数量', '状态');
- $d = array
- (
- '合计',
- round($refund_body_total['price'], 2),
- $refund_body_total['num'],
- '-'
- );
- if ($type == 3) {
- unset($head[1]);
- unset($d[1]);
- }
- $refund_body[] = $d;
- $html .= '<div class="layui-card"><div class="layui-card-header">缺货与报损商品</div><div class="layui-card-body" style="max-heights: 300px;overflow: auto;">' . $this->table($head, $refund_body) . '</div></div>';
- }
- if ($cash_type == 1) {
- if ($type == 1) {
-
- $cash_order = Dever::db('cash/order')->select(array('type' => $info['type'], 'type_id' => $info['type_id'], 'source_order_id' => $info['id']));
- } elseif ($type == 2) {
-
- $cash_order = Dever::db('cash/order')->select(array('source_type' => $info['source_type'], 'source_id' => $info['source_id'], 'source_order_id' => $info['id']));
- }
- }
-
- if (isset($cash_order) && $cash_order) {
- $head = array('序号', '结算单号', '数量', '金额', '结算类型', '入账状态', '审核状态', '结算时间', '审核未通过原因', '管理');
- if ($type == 3) {
- unset($head[3]);
- }
- $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['cash'];
- $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,
- );
- if ($type == 3) {
- unset($d[3]);
- }
- $body[] = $d;
- }
- $html .= '<div class="layui-card"><div class="layui-card-header">对账清单</div><div class="layui-card-body" style="max-heights: 500px;overflow: auto;">' . $this->table($head, $body) . '</div></div>';
-
- }
- $html .= '</div>';
- return '<div class="layui-card-body">' . $html . '</div>';
- }
- private function table($head, $data)
- {
- $html = '';
- if ($head) {
- $html = '<table class="layui-table">';
- $html .= '<thead><tr>';
- foreach ($head as $k => $v) {
- $html .= '<th>'.$v.'</th>';
- }
- $html .= '</tr></thead>';
- $html .= '<tbody>';
- foreach ($data as $k => $v) {
- $html .= '<tr>';
- foreach ($v as $k1 => $v1) {
- $html .= '<td>'.$v1.'</td>';
- }
- $html .= '</tr>';
- }
- $html .= '</tbody>';
- $html .= '</table>';
- } else {
- foreach ($data as $k => $v) {
- $html .= '';
- foreach ($v as $k1 => $v1) {
- $html .= $v1 . ' ';
- }
- $html .= '';
- }
- }
- return $html;
- }
-
-
-
- public function audit_commit()
- {
- $order_id = Dever::input('order_id');
- $order = Dever::db('shop/buy_order')->find($order_id);
- if (!$order || ($order && $order['status'] != 2)) {
- Dever::alert('当前订单状态无法拆单');
- }
- if ($order['type'] != 1) {
- Dever::alert('这不是门店的订单');
- }
- $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $order_id));
- $shop = Dever::db('shop/info')->find($order['type_id']);
-
- $shop_store = Dever::db('shop/store')->select(array('shop_id' => $shop['id']));
- $store = array();
- $distance = array();
-
- foreach ($shop_store as $k => $v) {
- $info = Dever::db('store/info')->find($v['store_id']);
- if ($info && $info['status'] == 1) {
- $distance[] = $info['distance'] = Dever::distance($shop['lng'], $shop['lat'], $info['lng'], $info['lat']);
- $store[] = $info;
- }
- }
- if (!$store) {
- Dever::alert('未分配仓库');
- }
- array_multisort($distance, SORT_ASC, SORT_NUMERIC, $store);
- $shop_factory = Dever::db('shop/factory')->select(array('shop_id' => $shop['id']));
- $factory = array();
- $distance = array();
-
- foreach ($shop_factory as $k => $v) {
- $info = Dever::db('factory/info')->find($v['factory_id']);
- if ($info && $info['status'] == 1) {
- $distance[] = $info['distance'] = Dever::distance($shop['lng'], $shop['lat'], $info['lng'], $info['lat']);
- $factory[] = $info;
- }
- }
- if (!$factory) {
- Dever::alert('未分配工厂');
- }
- array_multisort($distance, SORT_ASC, SORT_NUMERIC, $factory);
- $this->order_num = 0;
- $this->order_id = array();
- $delete = array();
- $yes = array();
-
- foreach ($goods as $k => $v) {
-
- $find = $this->store($order['id'], $order['order_num'] . '_' . $this->order_num, $shop, $store, $v);
- if (!$find[1]) {
-
- if ($factory) {
- $find = $this->factory($order['id'], $order['order_num'] . '_' . $this->order_num, $shop, $factory, $v);
- }
- }
- if ($find[1]) {
- $delete[$v['id']] = $v;
- } else {
- $yes[$v['id']] = $v;
- }
- }
- $num = count($this->order_id);
- if ($num > 0) {
- if ($num == 1) {
- $key = array_keys($this->order_id);
- $key = $key[0];
- Dever::db('shop/buy_order')->delete($key);
- $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $key));
- $p_price = 0;
- foreach ($goods as $k => $v) {
- $goods_info = Dever::db('shop/buy_order_goods')->find(array('order_id' => $order['id'], 'goods_id' => $v['goods_id']));
- if ($goods_info) {
- Dever::db('shop/buy_order_goods')->update(array('where_id' => $goods_info['id'], 'set_p_price' => $v['p_price']));
- $p_price += $v['p_price'];
- }
- }
- Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'status' => 3, 'source_type' => $this->order_id[$key][0], 'source_id' => $this->order_id[$key][1], 'p_price' => $p_price, 'operdate' => time()));
- Dever::db('shop/buy_order_goods')->delete(array('order_id' => $key));
- $this->order_id[$order['id']] = array($this->order_id[$key][0], $this->order_id[$key][1]);
- unset($this->order_id[$key]);
- } else {
- if (!$yes) {
- Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'state' => 2));
- Dever::load('cash/lib/order')->up($order, 1, 3);
- } else {
- $price = 0;
- $num = 0;
- foreach ($delete as $k => $v) {
- Dever::db('shop/buy_order_goods')->delete(array('where_id' => $v['id']));
- $price += $v['price'];
- $num += $v['num'];
- }
- $order['price'] = $order['price'] - $price;
- $order['num'] = $order['num'] - $num;
- Dever::db('shop/buy_order')->update(array('where_id' => $order['id'], 'price' => $order['price'], 'num' => $order['num']));
- Dever::load('shop/lib/refund')->set('buy')->apply(1, $shop['id'], $order_id, false, 3, 0, '供货商库存不足');
- Dever::load('cash/lib/order')->up($order, 1, 3);
- }
- }
- } else {
-
- Dever::load('shop/lib/refund')->set('buy')->apply(1, $shop['id'], $order_id, false, 3, 0, '供货商库存不足');
- }
- if ($this->order_id) {
- foreach ($this->order_id as $k => $v) {
- $this->sendMsg($v[0], $v[1], $k);
- if ($k != $order['id']) {
- $order_info = Dever::db('shop/buy_order')->find($k);
- Dever::load('cash/lib/order')->up($order_info, 1, 1);
- }
- }
- }
- return 'ok';
- }
- private function store($order_id, $order_num, $shop, $store, $goods, $state = 2)
- {
- $find = array();
- $type_id = array();
- $id = array();
- if (!$store) {
- return array(2, $type_id, $id);
- }
- foreach ($store as $k => $v) {
- $where['store_id'] = $v['id'];
- $where['goods_id'] = $goods['goods_id'];
- $where['sku_id'] = ($goods['sku_id'] && $goods['sku_id'] > 0) ? $goods['sku_id'] : -1;
- $sku = Dever::db('store/goods_sku')->getOne($where);
- if ($sku) {
- if ($goods['num'] <= $sku['total']) {
-
- $state = $this->createOrder($order_id, $order_num, 1, $shop['id'], 2, $where['store_id'], $goods['price'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
- if ($state) {
- $type_id[] = $where['store_id'];
- $id[] = $state;
- $this->order_id[$state] = array(2, $where['store_id']);
- break;
- }
- } elseif ($state == 1 && $sku['total'] > 0) {
-
- $goods['num'] = $goods['num'] - $sku['total'];
-
- $state = $this->createOrder($order_id, $order_num, 1, $shop['id'], 2, $where['store_id'], $goods['price'], $goods['price'], $sku['total'], $where['goods_id'], $where['sku_id']);
- if (!$state) {
- $goods['num'] = $goods['num'] + $sku['total'];
- } else {
- $type_id[] = $where['store_id'];
- $id[] = $state;
- $this->order_id[$state] = array(2, $where['store_id']);
- }
- continue;
- } else {
-
- continue;
- }
- }
- }
- return array(2, $type_id, $id);
- }
- private function factory($order_id, $order_num, $shop, $factory, $goods)
- {
- $find = array();
- $type_id = array();
- $id = array();
- if (!$factory) {
- return array(3, $type_id, $id);
- }
- foreach ($factory as $k => $v) {
- $where['factory_id'] = $v['id'];
- $where['goods_id'] = $goods['goods_id'];
- $where['sku_id'] = ($goods['sku_id'] && $goods['sku_id'] > 0) ? $goods['sku_id'] : -1;
- $sku = Dever::db('factory/goods_sku')->getOne($where);
- if ($sku && $sku['p_price'] > 0) {
- $state = $this->createOrder($order_id, $order_num, 1, $shop['id'], 3, $where['factory_id'], $goods['price'], $sku['p_price'], $goods['num'], $where['goods_id'], $where['sku_id']);
- if ($state) {
- $type_id[] = $where['factory_id'];
- $id[] = $state;
- $this->order_id[$state] = array(3, $where['factory_id']);
- break;
- }
- } else {
- continue;
- }
- }
- return array(3, $type_id, $id);
- }
-
- private function sendMsg($source_type, $source_id, $id)
- {
- if (Dever::project('message')) {
- $msg_param['type'] = 1;
- $msg_param['id'] = $id;
- $msg_param['source_id'] = $source_id;
- $msg_param['source_type'] = $source_type;
- $msg_param = Dever::json_encode($msg_param);
- $project = $source_type + 1;
- $msg = '您有一个新的订货单,请及时处理。';
- Dever::load('message/lib/data')->push(-1, $source_id, '订货通知', $msg, 2, $project, false, $msg_param);
- }
- }
-
- private function createOrder($order_id, $order_num, $type, $type_id, $source_type, $source_id, $price, $p_price, $num, $goods_id, $sku_id)
- {
- $where['parent_order_id'] = $order_id;
- $where['type'] = $type;
- $where['type_id'] = $type_id;
- $where['source_type'] = $source_type;
- $where['source_id'] = $source_id;
- $where['r'] = $goods_id;
- $info = Dever::db('shop/buy_order')->find($where);
- if (!$info) {
- $this->order_num++;
- $data = $where;
- $data['name'] = $order_id;
- $data['order_num'] = $order_num;
- $data['operdate'] = time();
- $data['status'] = 3;
- $data['price'] = $price * $num;
- $data['p_price'] = $p_price * $num;
- $data['num'] = $num;
- $data['refund_cash'] = 0;
- $data['refund_p_cash'] = 0;
- $id = $state = Dever::db('shop/buy_order')->insert($data);
- } else {
- $id = $info['id'];
- $data['where_id'] = $id;
- $data['price'] = $info['price'] + ($price * $num);
- $data['p_price'] = $info['p_price'] + ($p_price * $num);
- $data['num'] = $info['num'] + $num;
- $state = Dever::db('shop/buy_order')->update($data);
- }
- if ($state && $id > 0) {
- $goods_info = Dever::db('shop/buy_order_goods')->find(array('order_id' => $id));
- if (!$goods_info) {
- $goods['order_id'] = $id;
- $goods['goods_id'] = $goods_id;
- $goods['sku_id'] = $sku_id;
- $goods['price'] = $price;
- $goods['p_price'] = $p_price;
- $goods['num'] = $num;
- Dever::db('shop/buy_order_goods')->insert($goods);
- }
-
- return $id;
- }
- return false;
- }
-
- public function updateSell($source_type, $source_id, $goods_id, $sku_id, $num)
- {
- if ($source_type == 2) {
- $data['store_id'] = $source_id;
- $data['goods_id'] = $goods_id;
- $data['sku_id'] = $sku_id;
- $data['num'] = $num;
- return Dever::load('store/lib/goods')->oper($source_id, 1, 2, array($data));
- } else {
- $up = array();
- $up['where_factory_id'] = $source_id;
- $up['where_goods_id'] = $goods_id;
- $up['sell_num'] = $num;
- $state = Dever::db('factory/goods')->incSell($up);
- if ($state) {
- if ($sku_id > 0) {
-
- } else {
- $sku_id = -1;
- }
- $upSku = $up;
- $upSku['where_sku_id'] = $sku_id;
- $state = Dever::db('factory/goods_sku')->incSell($upSku);
- }
- return $state;
- }
- }
-
- public function printer($user)
- {
- $id = Dever::input('id');
- $type = Dever::input('type', 1);
- $factory_config = Dever::db('main/factory_config')->find();
- $main_config = Dever::db('main/config')->find();
- $config = Dever::db('shop/buy_order')->config;
- $info = Dever::db('shop/buy_order')->one($id);
- $source_info = Dever::db('factory/info')->find($info['source_id']);
- if ($type == 2) {
-
- $member = Dever::db('store/member')->find($user['id']);
- $name = '仓库名称';
- } else {
-
- $member = Dever::db('factory/member')->find($user['id']);
- $name = '工厂名称';
- }
- if ($info['type'] == 1) {
- $type_info = Dever::db('shop/info')->find($info['type_id']);
- } elseif ($info['type'] == 2) {
- $type_info = Dever::db('store/info')->find($info['type_id']);
- } elseif ($info['type'] == 3) {
- $type_info = Dever::db('store/info')->find($info['type_id']);
- }
- $cdate = date('Y-m-d H:i', $info['cdate']);
- if ($info['operdate']) {
- $operdate = date('Y-m-d H:i', $info['operdate']);
- } else {
- $operdate = '';
- }
- if ($info['fdate']) {
- $fdate = date('Y-m-d H:i', $info['fdate']);
- } else {
- $fdate = '';
- }
- $status = $config['status'][$info['status']];
- $info['ps_info'] = Dever::db('shop/buy_order_ps')->find(array('order_id' => $info['id']));
- if ($info['ps_info']) {
- $info['ps_info']['service_name'] = '供应商自送';
- $info['ps_info']['cdate'] = date('Y-m-d H:i', $info['ps_info']['cdate']);
- if ($info['ps_info']['ydate']) {
- $info['ps_info']['ydate'] = date('Y-m-d H:i', $info['ps_info']['ydate']);
- } else {
- $info['ps_info']['ydate'] = '无';
- }
- $ps_status = Dever::db('shop/buy_order_ps')->config['status'];
- $info['ps_info']['status_name'] = $status[$info['ps_info']['status']];
-
- if ($info['ps_info']['service_id'] > 0) {
-
- $service = Dever::db('shop/service')->find($info['ps_info']['service_id']);
- $info['ps_info']['service_name'] = $service['name'];
- }
- $info['ps_info']['order_num'] = str_replace("\r\n", ',', $info['ps_info']['order_num']);
- }
- $pdf = Dever::load('pdf/lib/base')->init();
- $pdf->hr('-', $main_config['name']);
- $pdf->br()->font(20)->center('订货单号:' . $info['order_num']);
- $pdf->font(10);
- $pdf->br();
- $pdf->br()->left($name . ':' . $type_info['name'], 80)->left('制单人:' . $member['name'], 60)->left('制单时间:' . date('Y-m-d H:i'), 40);
- $pdf->hr();
- if ($type == 2 && $info['type'] == 2) {
- $pdf->br()->left('订单状态:' . $status, 140)->left('订货时间:' . $operdate, 40);
- $pdf->hr();
- $pdf->br()->left('发货供应商:' . $source_info['name'], 140)->left('发货时间:' . $info['ps_info']['cdate'], 40);
- if ($info['ps_info']) {
- $pdf->br()->left('物流信息:' . $info['ps_info']['service_name'] . ' 物流单号:' . $info['ps_info']['order_num'], 140)->left('确认收货时间:' . $info['ps_info']['ydate'], 40);
- }
- $pdf->hr();
- } else {
- $pdf->br()->left('订单状态:' . $status, 80)->left('订货人:' . $type_info['truename'], 60)->left('订货时间:' . $operdate, 40);
- $pdf->hr();
- $pdf->br()->left('配送至:' . $type_info['name'], 150)->right('收件人联系方式:' . $type_info['truename'] . ',' . $type_info['mobile'], 40);
- $pdf->left('配送地址:' . $type_info['address']);
- $pdf->hr();
- if ($info['ps_info']) {
- $pdf->br()->left('发货时间:' . $info['ps_info']['cdate'], 80)->left('配货员::' . $info['ps_info']['phy'], 70)->left('打包员:' . $info['ps_info']['dby'], 40);
- $pdf->br()->left('包裹重量:' . $info['ps_info']['zl'] . '克', 80)->left('包裹体积:' . $info['ps_info']['tj'] . '立方厘米', 70)->left('包裹数量:' . $info['ps_info']['num'], 40);
- $pdf->br()->left('物流信息:' . $info['ps_info']['service_name'], 40);
- if ($info['ps_info']['order_num']) {
- $pdf->left('物流单号:' . $info['ps_info']['order_num'], 70);
- }
- $pdf->left('到货确认时间:' . $info['ps_info']['ydate']);
- $pdf->hr();
- }
- }
- $body = array();
- $body_total = array();
- $body_total['price'] = 0;
- $body_total['num'] = 0;
- $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
- $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
- $refund_body = array();
- $refund_body_total = array();
- $refund_body_total['price'] = 0;
- $refund_body_total['num'] = 0;
- foreach ($goods as $k => $v) {
- if ($type == 1) {
- $v['price'] = $v['p_price'];
- }
- $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
- $status = $goods_status[$v['status']];
- $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id'], 'type' => 2));
- if (isset($goods_info['sku'])) {
- $sku = $goods_info['sku']['string'];
- } else {
- $sku = '无';
- }
- $d = array
- (
- $goods_info['id'],
- $goods_info['name'],
- $sku,
- $v['price'],
- 'x ' . $v['num'],
- );
- if ($type == 2) {
- unset($d[3]);
- }
- if ($tk && $v['status'] == 3 && $tk['status'] != 3) {
- $refund_body[] = $d;
- $refund_body_total['price'] += $v['price'];
- $refund_body_total['num'] += $v['num'];
- } else {
- $body[] = $d;
- $body_total['price'] += $v['price'];
- $body_total['num'] += $v['num'];
- }
- }
- $head = array(array('商品编号', 40), array('商品名称', 60), array('商品属性', 40), array('单价', 40), array('数量', 20));
- if ($type == 2) {
- unset($head[3]);
- $head[1][1] = 70;
- $head[2][1] = 60;
- }
- if ($body) {
- $pdf->center('订单商品');
- $pdf->br();
- foreach ($head as $k => $v) {
- $pdf->left($v[0], $v[1]);
- }
- foreach ($body as $k => $v) {
- $pdf->br();
- foreach ($head as $k1 => $v1) {
- $pdf->left($v[$k1], $v1[1]);
- }
- }
- $pdf->br();
- $pdf->right('共'.$body_total['num'].'件商品,合计金额¥' . $body_total['price'] . '元');
- $pdf->hr();
- }
- if ($refund_body) {
- $pdf->center('缺货与报损商品');
- $pdf->br();
- foreach ($head as $k => $v) {
- $pdf->left($v[0], $v[1]);
- }
- foreach ($refund_body as $k => $v) {
- $pdf->br();
- foreach ($head as $k1 => $v1) {
- $pdf->left($v[$k1], $v1[1]);
- }
- }
- $pdf->br();
- if ($type == 2) {
- $pdf->right('共'.$body_total['num'].'件商品');
- } else {
- $pdf->right('共'.$body_total['num'].'件商品,合计金额¥' . $body_total['price'] . '元');
- }
-
- $pdf->hr();
-
- }
- $pdf->br(1);
-
- $pdf->right('如遇任何问题请致电客服');
- $pdf->br();
- $pdf->font(20);
- $pdf->left($main_config['name'], 160);
- $pdf->font(10);
- $pdf->right('电话:' . $factory_config['phone'], 30);
- $pdf->br();
- $pdf->left($main_config['site'], 160);
- $pdf->font(10);
- $pdf->right($main_config['worktime'], 30);
- $pdf->out('订货单');
- }
- }
|