123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- <?php
- namespace Scm\Lib;
- use Dever;
- class Order
- {
- public function updateGoods($id, $name, $data)
- {
- $table = Dever::input('table');
- $goods = Dever::param('goods', $data);
- $cash = Dever::param('cash', $data);
- if ($table && $goods) {
- $temp = explode('-', $goods);
- $update = array();
- $update['where_id'] = $id;
- $update['goods_id'] = $temp[0];
- $update['sku_id'] = $temp[1];
- $batch = Dever::param('batch', $data);
- if (!$batch) {
- $update['batch'] = date('Ymd');
- }
- if (isset($temp[2]) && !$cash) {
- //$update['cash'] = $temp[2];
- }
-
- Dever::db($table)->update($update);
- Dever::config('base')->hook = false;
- }
- }
- public function updateOrderNum($id, $name, $data)
- {
- $table = Dever::input('table');
- $prefix = Dever::input('prefix');
- if ($table && $prefix) {
- $servicer_store_id = Dever::param('servicer_store_id', $data);
- if ($servicer_store_id) {
- $info = Dever::db('scm_servicer/store')->find($servicer_store_id);
- if ($info && $info['type'] == 1 && (!$info['area'] || !$info['address'] || !$info['truename'] || !$info['tel'])) {
- Dever::db($table)->delete($id);
- Dever::alert('仓库[' . $info['name'] . ']收货地址未填写');
- }
- }
- $seller_shop_id = Dever::param('seller_shop_id', $data);
- if ($seller_shop_id) {
- $info = Dever::db('scm_seller/shop')->find($seller_shop_id);
- if ($info && $info['type'] == 1 && (!$info['area'] || !$info['address'] || !$info['truename'] || !$info['tel'])) {
- Dever::db($table)->delete($id);
- Dever::alert('门店[' . $info['name'] . ']收货地址未填写');
- }
- }
- $update['order_num'] = $this->getOrderNum($table, $prefix);
- $update['where_id'] = $id;
- Dever::db($table)->update($update);
- Dever::config('base')->hook = false;
- }
- }
- # 生成订单号
- public function getOrderNum($table, $prefix = 'C')
- {
- $where['order_num'] = Dever::order($prefix);
- $state = Dever::db($table)->one($where);
- if (!$state) {
- return $where['order_num'];
- } else {
- return $this->getOrderNum($table);
- }
- }
- # 查看订单详情
- public function show($order_table)
- {
- $id = Dever::input('order_id');
- $order_db = Dever::db($order_table);
- $order = $order_db->one($id);
- $order['config'] = $order_db->config['set'];
- $content = array();
- if (isset($order['type'])) {
- $type = Dever::db($order_table . '_type')->one($order['type']);
- $content[0][] = array('订单类型', $type['name']);
- }
- $content[0][] = array('订单状态', Dever::status($order['config']['status'], $order['status']));
- $content[0][] = array('下单时间', date('Y-m-d H:i', $order['cdate']));
- $order['info'] && $content[0][] = array('订单备注', $order['info']);
- $content[1] = $content[2] = array();
- $role = $this->show_role(array
- (
- 'seller' => '经销商',
- 'seller_shop' => '门店',
- 'servicer' => '配送商',
- 'servicer_store' => '仓库',
- 'supplier' => '供应商',
- ), $order, $content[1]);
- $this->show_audit($order, $content[2]);
- $result = array();
- $result[$order['order_num']] = array
- (
- 'type' => 'info',
- 'content' => $content
- );
- $this->show_address($order, $role, $result);
- $audit = Dever::input('audit');
- if ($audit == 1) {
- $this->show_goods_audit($order, $order_table, $result);
- } else {
- $this->show_goods($order, $order_table, $result);
- }
- $head = array
- (
- 'name' => '基本信息',
- 'btn' => $this->show_button($order, $order_table),
- );
- $html = Dever::show($head, $result);
- return $html;
- }
- # 显示订单角色
- private function show_role($role, $order, &$data)
- {
- $result = array();
- foreach ($role as $k => $v) {
- $col = $k . '_id';
- if (isset($order[$col]) && $order[$col] > 0) {
- $project = $k;
- $name = 'info';
- if (strstr($k, '_')) {
- $temp = explode('_', $k);
- $project = $temp[0];
- $name = $temp[1];
- }
- $table = 'scm_' . $project . '/' . $name;
- $result[$k] = Dever::db($table)->one($order[$col]);
- if ($result[$k]) {
- $data[] = array($v, $result[$k]['name']);
- }
- }
- }
- return $result;
- }
- # 显示审核信息
- private function show_audit($order, &$data)
- {
- if (isset($order['audit_admin']) && $order['audit_admin']) {
- $admin = Dever::db('manage/admin')->find($order['audit_admin']);
- $data = array
- (
- array('审核人', $admin['username']),
- array('审核状态', Dever::status($order['config']['audit'], $order['audit'])),
- array('审核备注', $order['audit_desc']),
- );
- }
- }
- # 显示订单地址
- private function show_address($order, $role, &$result)
- {
- if (!$order['address']) {
- if (isset($role['servicer_store'])) {
- $address = $role['servicer_store'];
- }
- if (isset($role['seller_shop'])) {
- $address = $role['seller_shop'];
- }
- } else {
- $address = Dever::json_decode($order['address']);
- }
- if ($address) {
- $address['area'] = Dever::load('area/api')->string($address['area']);
- $result['收货信息'] = array
- (
- 'type' => 'info',
- 'content' => array
- (
- array
- (
- array('联系人', $address['truename']),
- array('联系电话', $address['tel']),
- array('收货地址', $address['area'] . ',' . $address['address']),
- ),
- ),
- );
- }
- }
- # 显示订单商品清单
- private function show_goods($order, $order_table, &$result)
- {
- $data = Dever::db($order_table . '_goods')->select(array('order_id' => $order['id']));
- if ($data) {
- $table['head'] = array('商品编码', '商品名称', '批次', '单价', '数量', '总价', '状态');
- $table['body'] = array();
- $total_price = $total_num = 0;
- $status = Dever::db($order_table . '_goods')->config['status'];
- foreach ($data as $k => $v) {
- $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id'], $v['unit_id']);
- $status_name = Dever::status($status, $v['status']);
- $num = $v['num'];
- if ($v['status'] == 2 && $v['unit_id'] != $goods_info['base_unit_id']) {
- if (!isset($order['supplier_id'])) {
- $order['supplier_id'] = false;
- }
- $unit = Dever::load('scm/lib/unit')->convertBase($v['goods_id'], $v['sku_id'], $v['unit_id'], $v['num'], $v['cash'], 0, $order['supplier_id']);
- if ($unit) {
- $base_unit = Dever::db('scm/unit')->find($unit['unit_id']);
- $goods_info['unit'] .= ' => '.$unit['num'].''.$base_unit['name'].'';
- $num = $unit['num'];
- }
- }
- $cash = Dever::number($v['cash'] * $v['num']);
- $detail = array
- (
- $goods_info['code'],
- $goods_info['aname'],
- );
- if (isset($v['batch'])) {
- $detail[] = $v['batch'] . (isset($v['sdate']) && $v['sdate'] ? '[' . date('Y-m-d', $v['sdate']) . '生产]' : '');
- } else {
- unset($table['head'][3]);
- }
- $detail[] = $v['cash'];
- $detail[] = $v['num'] . $goods_info['unit'];
- $detail[] = $cash;
- $detail[] = $status_name;
- if ($goods_info['goods']) {
- $detail['goods'] = $goods_info['goods'];
- }
- $table['body'][] = $detail;
- $total_price += $cash;
- $total_num += $num;
- }
- $result['商品清单'] = array
- (
- 'type' => 'table',
- 'head' => array('name' => '', 'btn' => ''),
- 'content' => $table,
- 'total' => '合计金额:' . Dever::number($total_price) . ',合计数量:' . $total_num
- );
- }
- }
- # 显示按钮
- private function show_button($order, $order_table)
- {
- $button = array();
- if ($order['status'] == 1) {
- list($project, $table) = explode('/', $order_table);
- $url = Dever::url('project/database/update?project='.$project.'&table='.$table.'&where_id='.$order['id'].'&col=audit,audit_desc', 'manage');
- $button[] = array
- (
- 'type' => 'edit',
- 'link' => $url,
- 'name' => '审核',
- );
- }
- return $button;
- }
- private function show_goods_audit($order, $order_table, &$result)
- {
- $order['type'] = 1;
- $data = Dever::db($order_table . '_goods')->select(array('order_id' => $order['id']));
- print_r($order);die;
- $seller = Dever::db('scm_seller/info')->find($order['seller_shop_id']);
- $seller = Dever::db('scm_seller/shop')->find($order['seller_shop_id']);
- list($assign, $source) = Dever::load('scm/lib/assign')->get($goods, $info, $shop, true);
- if ($info) {
- $head = array('商品编码', '商品名称', '批次', '单价', '数量', '总价', '供货商');
- $body = array();
- $i = 0;
- if ($data) {
- foreach ($assign as $k => $v) {
- foreach ($v as $v1) {
- $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
- if (isset($goods_info['sku'])) {
- $sku = '[' . $goods_info['sku']['string'] . ']';
- } else {
- $sku = '';
- }
- $d = array
- (
- $i+1,
- $goods_info['code'],
- $goods_info['name'] . $sku,
- $this->getSelect($source, $v1['source_id'], $v1['order_goods_id']),
- $v1['num'],
- $goods_info['unit'],
- $v1['p_price'] * $v1['num'],
- );
- $body[] = $d;
- $i++;
- }
- }
- }
-
- if ($goods) {
- foreach ($goods as $k => $v) {
- $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
- if (isset($goods_info['sku'])) {
- $sku = '[' . $goods_info['sku']['string'] . ']';
- } else {
- $sku = '';
- }
- $d = array
- (
- $i+1,
- $goods_info['code'],
- $goods_info['name'] . $sku,
- $this->getSelect($source, false, $v['id']),
- $v['num'],
- $goods_info['unit'],
- $v['p_price'] * $v['num'],
- );
- $body[] = $d;
- $i++;
- }
- }
- $btn = array();
- $btn[] = array(
- 'type' => 'click',
- 'content' => 'setAudit()',
- 'name' => '全部调整<script>function setAudit(){layer.confirm(\'确定进行此项操作吗?\', function(){var audit = $(\'.audit_set\').val();$(\'.audit\').each(function(){$(this).val(audit);layui.form.render();layer.closeAll()})})}</script>'
- );
- $result['商品拆单'] = array
- (
- 'type' => 'table',
- 'head' => array('name' => '供货商:' . $this->getSelect($source, false, false), 'btn' => $btn),
- 'content' => array
- (
- 'head' => $head,
- 'body' => $body,
- )
- );
- $url = Dever::url('lib/buy.audit_set_commit?json=1&order_id=' . $info['id'], 'mshop');
- $result['审核结果'] = array
- (
- 'type' => 'html',
- 'content' => '<script>function saveAudit(){var goods = [];var audit = 1; var audit_text = $(".update_audit_text").val();$(".update_audit").each(function(){if ($(this).get(0).checked){audit = $(this).val()}});$(\'.audit\').each(function(){var v = $(this).val();var id = $(this).attr("id");goods.push(v + "_" + id);});layer.confirm(\'确定进行此项操作吗?\', function(){layui.form.render();var send = {};send.goods = goods.join(",");send.audit = audit;send.audit_text = audit_text;console.info(send);$.post("'.$url.'", send, function(t){t = JSON.parse(t);showYes(t)})})}</script><style>.layui-form-radio{padding-right: 0px;margin: 0px 0px 0 0;margin-left:40px}</style><div class="layui-form-item show_input"><div classs="layui-col-lg6"><div><label style="font-size:14px;font-weight:bold;" class="">审核状态</label><div style="display:inline" class="am-btn-group"><input update_type="checked" class="checkbox-checkall-0_update_audit update_audit update_value validate[required]" type="radio" name="update_audit[]" value="2" checked="" show_id="audit" autocomplete="off" id="form-validation-field-1"> 审核通过 <input update_type="checked" class="autoload checkbox-checkall-0_update_audit update_audit update_value validate[required]" type="radio" name="update_audit[]" value="3" autocomplete="off" id="form-validation-field-0"> 审核未通过 </div></div></div></div><div class="layui-form-item" style="display: block;"><div classs="layui-col-lg6"><div><label style="font-size:14px;font-weight:bold;" class="">审核备注</label></div><div><textarea style="height:100px;" update_type="value" class="update_value update_audit_text form-control layui-input validate[required]" name="update_desc"></textarea></div></div></div> <div style="text-align:left" class="layui-layer-btn layui-layer-btn-"><a class="layui-btn layui-btn-primary" onclick="saveAudit()">保存</a><a class="layui-layer-btn1" style="display:none">取消</a></div>',
- );
- }
- }
- }
|