123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585 |
- <?php
- namespace Agent\Lib;
- use Dever;
- class Order
- {
-
- public function action($mid)
- {
- if ($mid > 0) {
- $member = Dever::db('agent/member')->find($mid);
- if (!$member) {
- Dever::alert('代理商不存在');
- }
- $mobile = $member['mobile'];
- $parent_mid = $member['parent_mid'];
- $data['type'] = $data['type'];
- $data['name'] = $data['name'];
- $data['idcard'] = $data['idcard'];
- $data['idcard_front'] = $data['idcard_front'];
- $data['idcard_back'] = $data['idcard_back'];
- } else {
- $mobile = Dever::input('mobile');
- $where['mobile'] = Dever::load('agent/lib/member')->checkMobile($mobile);
- $member = Dever::db('agent/member')->find($where);
- if ($member) {
- Dever::alert('注册失败,手机号已存在');
- }
- $member = Dever::db('agent/member')->find();
- if ($member) {
- $parent_member = Dever::load('agent/lib/member')->checkCode();
- $parent_mid = $parent_member['id'];
- } else {
- $parent_mid = -1;
- }
- $data['type'] = Dever::input('type', 1);
- $data['name'] = Dever::input('name');
- $data['idcard'] = Dever::input('idcard');
- $data['idcard_front'] = Dever::input('idcard_front');
- $data['idcard_back'] = Dever::input('idcard_back');
- }
-
- $data['mobile'] = $mobile;
- $data['parent_mid'] = $parent_mid;
- if ($data['type'] == 1) {
- $name = '姓名';
- $idcard_name = '身份证号';
- if (!$data['idcard_front']) {
- Dever::alert('身份证正面不能为空');
- }
- if (!$data['idcard_back']) {
- Dever::alert('身份证反面不能为空');
- }
- } else {
- $name = '公司名称';
- $idcard_name = '营业执照号码';
- if (!$data['idcard_front']) {
- Dever::alert('营业执照不能为空');
- }
- }
- if (!$data['name']) {
- Dever::alert($name . '不能为空');
- }
- if (!$data['idcard']) {
- Dever::alert($idcard_name . '不能为空');
- }
- $data += $this->getPrice();
- $data['sign'] = Dever::input('sign');
- if (!$data['sign']) {
- Dever::alert('手写签名不能为空');
- }
- $data['order_num'] = $this->getOrderId();
-
- $data['pay_type'] = Dever::input('pay_type', 1);
- if ($data['pay_type'] == 3) {
- $data['bank_id'] = Dever::input('bank_id');
- if (!$data['bank_id']) {
- Dever::alert('请选择银行');
- }
- $data['bank_card'] = Dever::input('bank_card');
- if (!$data['bank_card']) {
- Dever::alert('请输入银行卡号');
- }
- } elseif ($data['pay_type'] == 2) {
-
- $data['pay_pic'] = Dever::input('pay_pic');
- if (!$data['pay_pic']) {
- Dever::alert('请上传打款凭证');
- }
- } elseif ($data['pay_type'] == 1) {
- Dever::alert('暂时不支持在线支付');
- $data['openid'] = Dever::input('openid');
- if (!$data['openid']) {
- Dever::alert('请先授权');
- }
- } else {
- Dever::alert('付款方式不正确');
- }
- $where['mobile'] = $data['mobile'];
- $where['role'] = $data['role'];
- $where['area'] = $data['area'];
- $info = Dever::db('agent/order')->find($where);
- if ($info && $info['status'] != 5) {
- Dever::alert('请勿重复提交');
- }
- $data['id'] = Dever::db('agent/order')->insert($data);
- if ($data['id']) {
- $result = array();
- $result['msg'] = '您的申请已经提交完成,请耐心等待,我们将在工作日8小时内为您通过审核,非常感谢。';
- if ($data['pay_type'] == 3) {
- $result['bank_msg'] = '您需要使用银行卡:所有人('.$data['name'].'),账号('.$data['bank_card'].'),转账至如下账户('.$data['price_str'].'):';
- $config = Dever::db('setting/base')->find();
- $result['bank_user'] = $config['bank_user'];
- $result['bank_name'] = $config['bank_name'];
- $result['bank_card'] = $config['bank_card'];
- } elseif ($data['pay_type'] == 1) {
-
- $result['pay'] = $this->pay($data);
- }
- return $result;
- } else {
- Dever::alert('登录失败');
- }
- }
-
- public function pay($data)
- {
- $param = array
- (
- 'project_id' => 2,
- 'channel_id' => 1,
- 'system_source' => 5,
- 'account_id' => 7,
- 'uid' => $data['id'],
- 'name' => $data['name'],
- 'openid' => $data['openid'],
- 'cash' => $data['price'],
- 'product_id' => $data['id'],
- 'order_id' => $data['order_num'],
- 'refer' => Dever::input('refer'),
- );
- $receipt = Dever::input('receipt');
- if ($receipt) {
- $param['receipt'] = $receipt;
- }
- $result = Dever::load('pay/api.pay', $param);
- $result['order_num'] = $data['order_num'];
- $result['order_id'] = $data['id'];
- return $result;
- }
-
- public function getOrderId()
- {
- $where['order_num'] = Dever::order('D');
- $state = Dever::db('agent/order')->one($where);
- if (!$state) {
- return $where['order_num'];
- } else {
- return $this->getOrderId();
- }
- }
-
- 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 'agent_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 getPrice()
- {
- $data['role'] = Dever::input('role');
- if (!$data['role']) {
- Dever::alert('代理类型不能为空');
- }
- $role = Dever::db('setting/role')->find($data['role']);
- if (!$role) {
- Dever::alert('代理类型不正确');
- }
- $data['area'] = Dever::input('area');
- if (!$data['area']) {
- Dever::alert('代理区域不能为空');
- }
-
- if ($role['type'] == 1) {
- $data['price'] = $role['price'];
- } elseif ($role['type'] == 2) {
- $data['price'] = Dever::load('area/api')->getPrice($role['area'], $data['area']);
- if ($data['price'] <= 0) {
- Dever::alert('代理区域的代理价格为空,请联系客服');
- }
- } else {
- Dever::alert('代理类型不正确');
- }
- if ($data['price'] >= 10000) {
- $data['price_str'] = ($data['price']/10000) . '万元';
- } else {
- $data['price_str'] = $data['price'] . '元';
- }
- if (is_int($data['price'])) {
- $data['price_str'] .= '整';
- }
- return $data;
- }
-
- public function show()
- {
- $id = Dever::input('order_id');
- $config = Dever::db('agent/order')->config['set'];
- $info = Dever::db('agent/order')->one($id);
- $process = Dever::db('agent/order_process')->getData($id);
- $status = $config['status'][$info['status']];
- $member = array();
- if ($info['mid'] > 0) {
- $member = Dever::db('agent/member')->find($info['mid']);
- }
-
- $parent_member = array();
- if ($info['parent_mid'] > 0) {
- $parent_member = Dever::db('agent/member')->find($info['parent_mid']);
- }
- $cdate = date('Y-m-d H:i', $info['cdate']);
- if ($info['fdate']) {
- $fdate = date('Y-m-d H:i', $info['fdate']);
- } else {
- $fdate = '';
- }
- if (!$member) {
- $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']),
- 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']),
- ),
- ),
- );
- }
- }
- 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 = '无';
- }
- $d = array
- (
- 'pic' => $goods_info['cover'],
- 'name' => $goods_info['name'],
- 'sku' => $sku,
- 'price' => $v['price'],
- 'num' => $v['num'],
- 'status' => $status,
- );
- 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,
- );
- }
-
- $head = array
- (
- 'name' => '基本信息',
- 'btn' => array(),
- );
- $html = Dever::show($head, $result);
- return $html;
- }
- }
|