123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- use think\facade\Db;
- class Memberbuy extends MobileMember
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/buy.lang.php');
- }
-
- public function buy_step1()
- {
- $cart_id = explode(',', input('param.cart_id'));
- $logic_buy = model('buy', 'logic');
- $transport_model = model('transport');
- $chain_model = model('chain');
-
- $member_model = model('member');
- $member_info = $member_model->getMemberInfoByID($this->member_info['member_id']);
- if (!$member_info['is_buylimit']) {
- ds_json_encode(10001, lang('cart_buy_noallow'));
- }
- if (config('ds_config.member_auth') && $this->member_info['member_auth_state'] != 3) {
- ds_json_encode(10001, lang('cart_buy_noauth'));
- }
-
-
- $ifcart = !empty(input('param.ifcart')) ? true : false;
-
- $pintuan_id = intval(input('param.pintuan_id'));
- $extra = array();
- if ($pintuan_id > 0) {
- $extra['pintuan_id'] = $pintuan_id;
-
- $extra['pintuangroup_id'] = empty(input('param.pintuangroup_id')) ? 0 : intval(input('param.pintuangroup_id'));
- }
-
- $bargainorder_id = intval(input('param.bargainorder_id'));
- if ($bargainorder_id > 0) {
- $extra['bargainorder_id'] = $bargainorder_id;
- }
- $result = $logic_buy->buyStep1($cart_id, $ifcart, $this->member_info['member_id'], $this->member_info['store_id'], $extra);
- if (!$result['code']) {
- ds_json_encode(10001, $result['msg']);
- } else {
- $result = $result['data'];
- }
- if (intval(input('post.address_id')) > 0) {
- $result['address_info'] = model('address')->getDefaultAddressInfo(array('address_id' => intval(input('post.address_id')), 'member_id' => $this->member_info['member_id']));
- }
- if ($result['address_info']) {
- $data_area = $logic_buy->changeAddr($result['freight_list'], $result['address_info']['city_id'], $result['address_info']['area_id'], $this->member_info['member_id']);
- if (!empty($data_area) && $data_area['state'] == 'success') {
- if (is_array($data_area['content'])) {
- foreach ($data_area['content'] as $store_id => $value) {
- $data_area['content'][$store_id] = ds_price_format($value);
- }
- }
- }
- }
-
- foreach ($result['store_cart_list'] as $key => $val) {
- foreach ($val as $kk => $vv) {
- $transport = $transport_model->getTransportInfo(array('transport_id' => $vv['transport_id']));
- if (is_array($transport) && $transport['transport_is_limited'] == 1) {
- $extend_list = $transport_model->getTransportextendList(array('transport_id' => $vv['transport_id']));
- if (is_array($extend_list)) {
- foreach ($extend_list as $k => $v) {
- if ($v['transportext_area_id'] != '') {
- if (strpos($v['transportext_area_id'], "," . $result['address_info']['city_id'] . ",") === false) {
- $result['store_cart_list'][$key][$kk]['limit'] = true;
- } else {
- $result['store_cart_list'][$key][$kk]['limit'] = false;
- }
- }
- }
- } else {
- $result['store_cart_list'][$key][$kk]['limit'] = false;
- }
- } else {
- $result['store_cart_list'][$key][$kk]['limit'] = false;
- }
- }
- }
-
- $store_cart_list = array();
- $store_total_list = $result['store_goods_total'];
- foreach ($result['store_cart_list'] as $key => $value) {
- $store_cart_list[$key]['goods_list'] = $value;
- $store_cart_list[$key]['store_goods_total'] = $result['store_goods_total'][$key];
- $store_cart_list[$key]['store_goods_original_total'] = $result['store_goods_original_total'][$key];
- $store_cart_list[$key]['store_goods_discount_total'] = $result['store_goods_discount_total'][$key];
- $store_cart_list[$key]['store_mansong_rule_list'] = isset($result['store_mansong_rule_list'][$key]) ? $result['store_mansong_rule_list'][$key] : '';
- if ($store_cart_list[$key]['store_mansong_rule_list'] && $store_cart_list[$key]['store_mansong_rule_list']['discount'] > 0) {
- $store_total_list[$key] -= $store_cart_list[$key]['store_mansong_rule_list']['discount'];
- }
- if (isset($result['store_voucher_list'][$key]) && is_array($result['store_voucher_list'][$key]) && count($result['store_voucher_list'][$key]) > 0) {
- current($result['store_voucher_list'][$key]);
- $store_cart_list[$key]['store_voucher_info'] = reset($result['store_voucher_list'][$key]);
- $store_cart_list[$key]['store_voucher_info']['voucher_price'] = ds_price_format($store_cart_list[$key]['store_voucher_info']['voucher_price']);
- $store_cart_list[$key]['store_voucher_info']['voucher_enddate_text'] = date('Y年m月d日', $store_cart_list[$key]['store_voucher_info']['voucher_enddate']);
-
- } else {
- $store_cart_list[$key]['store_voucher_info'] = array();
- }
- $store_cart_list[$key]['store_voucher_list'] = isset($result['store_voucher_list'][$key]) ? array_values($result['store_voucher_list'][$key]) : array();
- if (!empty($result['cancel_calc_sid_list'][$key])) {
- $store_cart_list[$key]['freight'] = '0';
- $store_cart_list[$key]['freight_message'] = $result['cancel_calc_sid_list'][$key]['desc'];
- }
- $store_cart_list[$key]['store_name'] = $value[0]['store_name'];
- $store_cart_list[$key]['store_id'] = $value[0]['store_id'];
- }
- foreach ($result['mall_voucher_list'] as $key => $value) {
- $result['mall_voucher_list'][$key]['mallvoucheruser_price'] = ds_price_format($result['mall_voucher_list'][$key]['mallvoucheruser_price']);
- $result['mall_voucher_list'][$key]['mallvoucheruser_enddate_text'] = date('Y年m月d日', $result['mall_voucher_list'][$key]['mallvoucheruser_enddate']);
- }
- $buy_list = array();
- $buy_list['if_presell'] = $result['if_presell'];
- $buy_list['presell_deposit_amount'] = $result['presell_deposit_amount'];
- $buy_list['store_cart_list'] = $store_cart_list;
- $buy_list['store_cart_list_api'] = array_values($store_cart_list);
- $buy_list['pay_goods_list'] = $result['pay_goods_list'];
- $buy_list['freight_hash'] = $result['freight_list'];
- $buy_list['address_info'] = $result['address_info'];
- $buy_list['ifshow_offpay'] = $result['ifshow_offpay'];
- $buy_list['vat_deny'] = $result['vat_deny'];
- $buy_list['vat_hash'] = $result['vat_hash'];
- $buy_list['inv_info'] = $result['inv_info'];
- $buy_list['available_predeposit'] = isset($result['available_predeposit']) ? $result['available_predeposit'] : array();
- $buy_list['available_rc_balance'] = isset($result['available_rc_balance']) ? $result['available_rc_balance'] : array();
- $buy_list['member_paypwd'] = isset($result['member_paypwd']) ? $result['member_paypwd'] : false;
- $buy_list['zk_list'] = isset($result['zk_list']) ? $result['zk_list'] : array();
- $buy_list['mall_voucher_list'] = $result['mall_voucher_list'];
- $buy_list['limit'] = false;
-
- foreach ($buy_list['store_cart_list'] as $key => $val) {
- foreach ($val['goods_list'] as $k => $v) {
- }
- if ($v['limit'] == true) {
- $buy_list['limit'] = true;
- }
- }
- if (isset($data_area['content']) && $data_area['content']) {
- $store_total_list = model('buy_1', 'logic')->reCalcGoodsTotal($store_total_list, $data_area['content'], 'freight');
- }
- $buy_list['order_amount'] = ds_price_format(array_sum($store_total_list));
- $buy_list['address_api'] = (isset($data_area) && $data_area) ? $data_area : '';
- foreach ($store_total_list as $store_id => $value) {
- $store_total_list[$store_id] = ds_price_format($value);
- }
- $buy_list['store_final_total_list'] = $store_total_list;
- ds_json_encode(10000, '', $buy_list);
- }
-
- public function buy_step2()
- {
- $param = array();
- $param['ifcart'] = input('post.ifcart');
- $param['cart_id'] = explode(',', input('post.cart_id'));
- $param['address_id'] = input('post.address_id');
- $param['vat_hash'] = input('post.vat_hash');
- $param['offpay_hash'] = input('post.offpay_hash');
- $param['offpay_hash_batch'] = input('post.offpay_hash_batch');
- $param['pay_name'] = input('post.pay_name');
- $param['invoice_id'] = input('post.invoice_id');
- $param['pintuan_id'] = input('post.pintuan_id');
- $param['pintuangroup_id'] = input('post.pintuangroup_id');
-
- $bargainorder_id = intval(input('param.bargainorder_id'));
- if ($bargainorder_id > 0) {
- $param['bargainorder_id'] = $bargainorder_id;
- }
-
- $voucher = array();
- $post_voucher = explode(',', input('post.voucher'));
- if (!empty($post_voucher)) {
- foreach ($post_voucher as $value) {
- list($vouchertemplate_id, $store_id, $voucher_price) = explode('|', $value);
- $voucher[$store_id] = $value;
- }
- }
- $param['voucher'] = $voucher;
-
- $mallvoucher = array();
- $post_mallvoucher = input('post.mallvoucher');
- if (!empty($post_mallvoucher)) {
- list($mallvoucheruser_voucherid, $mallvoucheruser_price) = explode('|', $post_mallvoucher);
- $mallvoucher = $post_mallvoucher;
- }
- $param['mallvoucher'] = $mallvoucher;
- $pay_message = trim(input('post.pay_message'), ',');
- $pay_message = explode(',', $pay_message);
- $param['pay_message'] = array();
- if (is_array($pay_message) && $pay_message) {
- foreach ($pay_message as $v) {
- if (strpos($v, '|') !== false) {
- $v = explode('|', $v);
- $param['pay_message'][$v[0]] = $v[1];
- }
- }
- }
-
- $chain_goods = array();
- $post_chain_goods = input('post.chain_goods');
- if (!empty($post_chain_goods)) {
- $post_chain_goods = explode(',', $post_chain_goods);
- if (!empty($post_chain_goods)) {
- foreach ($post_chain_goods as $value) {
- list($store_id, $chain_id) = explode('|', $value);
- $chain_goods[$store_id] = $chain_id;
- }
- }
- }
- $param['pd_pay'] = input('post.pd_pay');
- $param['rcb_pay'] = input('post.rcb_pay');
- $param['password'] = input('post.password');
- $param['fcode'] = input('post.fcode');
- $param['order_from'] = 2;
- $param['chain_goods'] = $chain_goods;
- $param['presell_pay'] = input('post.presell_pay');
- $logic_buy = model('buy', 'logic');
-
-
- $result = $logic_buy->buyStep2($param, $this->member_info['member_id'], $this->member_info['member_name'], $this->member_info['member_email']);
- if (!$result['code']) {
- ds_json_encode(10001, $result['msg']);
- }
- $order_info = current($result['data']['order_list']);
- ds_json_encode(10000, '', array('pay_sn' => $result['data']['pay_sn'], 'payment_code' => $order_info['payment_code']));
- }
-
- public function check_password()
- {
- if (empty(input('post.password'))) {
- ds_json_encode(10001, lang('param_error'));
- }
- $member_model = model('member');
- $member_info = $member_model->getMemberInfoByID($this->member_info['member_id']);
- if ($member_info['member_paypwd'] == md5(input('post.password'))) {
- ds_json_encode(10000, '', 1);
- } else {
- ds_json_encode(10001, lang('password_mistake'));
- }
- }
-
- public function change_address()
- {
- $logic_buy = model('buy', 'logic');
- $city_id = input('post.city_id');
- $area_id = input('post.area_id');
- if (empty($city_id)) {
- $city_id = $area_id;
- }
- $data = $logic_buy->changeAddr(input('post.freight_hash'), $city_id, $area_id, $this->member_info['member_id']);
- if (!empty($data) && $data['state'] == 'success') {
- ds_json_encode(10000, '', $data);
- } else {
- ds_json_encode(10001, lang('ds_common_op_fail'));
- }
- }
-
- public function pay()
- {
- $pay_sn = input('post.pay_sn');
- if (!preg_match('/^\d{20}$/', $pay_sn)) {
- ds_json_encode(10001, lang('param_error'));
- }
-
- $order_model = model('order');
- $pay_info = $order_model->getOrderpayInfo(array(
- 'pay_sn' => $pay_sn, 'buyer_id' => $this->member_info['member_id']
- ));
- if (empty($pay_info)) {
- ds_json_encode(10001, lang('cart_order_pay_not_exists'));
- }
-
- $condition = array();
- $condition[] = array('pay_sn', '=', $pay_sn);
- $condition[] = array('order_state', 'in', array(ORDER_STATE_NEW, ORDER_STATE_DEPOSIT, ORDER_STATE_REST, ORDER_STATE_PAY, ORDER_STATE_PICKUP));
- $order_list = $order_model->getOrderList($condition);
- if (empty($order_list)) {
- ds_json_encode(10001, lang('no_order_paid_was_found'));
- }
-
- $pay = array();
-
-
- $pay['pay_amount'] = 0;
-
- $pay['payed_rcb_amount'] = 0;
-
- $pay['payed_pd_amount'] = 0;
-
- $pay['pay_diff_amount'] = 0;
-
- $pay['member_available_pd'] = 0;
- $pay['member_available_rcb'] = 0;
- $logic_order = model('order', 'logic');
-
- foreach ($order_list as $key => $order_info) {
- if (!in_array($order_info['payment_code'], array('offline', 'chain'))) {
- if ($order_info['order_state'] == ORDER_STATE_NEW || $order_info['order_state'] == ORDER_STATE_DEPOSIT || $order_info['order_state'] == ORDER_STATE_REST) {
- $pay['payed_rcb_amount'] += $order_info['rcb_amount'];
- $pay['payed_pd_amount'] += $order_info['pd_amount'];
- if ($order_info['order_state'] == ORDER_STATE_DEPOSIT) {
- $pay['pay_diff_amount'] += $order_info['presell_deposit_amount'] - $order_info['rcb_amount'] - $order_info['pd_amount'];
- } else {
- $pay['pay_diff_amount'] += $order_info['order_amount'] - $order_info['presell_deposit_amount'] + $order_info['presell_pd_amount'] + $order_info['presell_rcb_amount'] - $order_info['rcb_amount'] - $order_info['pd_amount'];
- }
- }
- }
- }
- if (isset($order_info['chain_id']) && $order_info['payment_code'] == 'chain') {
- $order_list[0]['order_remind'] = sprintf(lang('chain_order_remind'), CHAIN_ORDER_PAYPUT_DAY);
- $flag_chain = 1;
- }
-
- if (empty($pay['pay_diff_amount'])) {
- ds_json_encode(12001, lang('pay_repeat'));
- }
- $condition = array();
- $condition[] = array('payment_platform', '=', 'h5');
- $payment_list = model('payment')->getPaymentOpenList($condition);
- if (!empty($payment_list)) {
- foreach ($payment_list as $k => $value) {
- unset($payment_list[$k]['payment_config']);
- unset($payment_list[$k]['payment_state']);
- unset($payment_list[$k]['payment_state_text']);
- }
- }
- if (in_array($this->member_info['member_clienttype'], array('ios', 'android'))) {
- foreach ($payment_list as $k => $value) {
- if (!strpos($payment_list[$k]['payment_code'], 'app')) {
- unset($payment_list[$k]);
- }
- }
- }
-
- $pay['member_available_pd'] = $this->member_info['available_predeposit'];
- $pay['member_available_rcb'] = $this->member_info['available_rc_balance'];
- $pay['member_paypwd'] = $this->member_info['member_paypwd'] ? true : false;
- $pay['pay_sn'] = $pay_sn;
- $pay['payed_amount'] = ds_price_format($pay['payed_rcb_amount'] + $pay['payed_pd_amount']);
- unset($pay['payed_pd_amount']);
- unset($pay['payed_rcb_amount']);
- $pay['pay_amount'] = ds_price_format($pay['pay_diff_amount']);
- unset($pay['pay_diff_amount']);
- $pay['member_available_pd'] = ds_price_format($pay['member_available_pd']);
- $pay['member_available_rcb'] = ds_price_format($pay['member_available_rcb']);
- $pay['payment_list'] = $payment_list ? array_values($payment_list) : array();
- ds_json_encode(10000, '', array('pay_info' => $pay));
- }
-
- public function check_pd_pwd()
- {
- if (empty(input('post.password'))) {
- ds_json_encode(10001, lang('param_error'));
- }
- $buyer_info = model('member')->getMemberInfoByID($this->member_info['member_id']);
- if ($buyer_info['member_paypwd'] != '') {
- if ($buyer_info['member_paypwd'] === md5(input('post.password'))) {
- ds_json_encode(10000, '', 1);
- }
- }
- ds_json_encode(10001, lang('payment_password_error'));
- }
-
- public function check_fcode()
- {
- $goods_id = intval(input('post.goods_id'));
- if ($goods_id <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- if (input('post.fcode') == '') {
- ds_json_encode(10001, lang('param_error'));
- }
- $result = model('buy', 'logic')->checkFcode($goods_id, trim(input('post.fcode')));
- if ($result['code']) {
- ds_json_encode(10000, '', 1);
- } else {
- ds_json_encode(10001, $result['msg']);
- }
- }
-
- public function chain_list()
- {
- $chain_model = model('chain');
- $area_id = input('param.area_id');
- $goods_list = input('param.goods_list');
- $goods_list = json_decode(htmlspecialchars_decode($goods_list), true);
- $allchain_list = array();
- $chain_idsarr = array();
- $onechain_id = array();
- foreach ($goods_list as $key => $val) {
- if ($val['bl_id'] == 1) {
- foreach ($val['bl_goods_list'] as $k => $v) {
- $chain_ids = Db::name('chain_goods')->where(array(array('goods_id', '=', $v['goods_id']), array('goods_storage', '>=', 1)))->column('chain_id');
- if ($key == 0) {
- $onechain_id = $chain_ids;
- $chain_idsarr = array_intersect($onechain_id, $chain_ids);
- } else {
- $chain_idsarr = array_intersect($chain_idsarr, $chain_ids);
- }
- }
- } else {
- $chain_ids = Db::name('chain_goods')->where(array(array('goods_id', '=', $val['goods_id']), array('goods_storage', '>=', $val['goods_num'])))->column('chain_id');
- if ($key == 0) {
- $onechain_id = $chain_ids;
- $chain_idsarr = array_intersect($onechain_id, $chain_ids);
- } else {
- $chain_idsarr = array_intersect($chain_idsarr, $chain_ids);
- }
- }
- }
- foreach ($goods_list as $key => $val) {
- $condition = array();
- $condition[] = array('chain_if_pickup', '=', 1);
- $condition[] = array('chain_id', 'in', $chain_idsarr);
- if ($area_id) {
- $condition[] = array('chain_area_2|chain_area_3', '=', $area_id);
- }
- $chain_list = $chain_model->getChainOpenList($condition);
- $allchain_list[] = $chain_list;
- }
- $chain_list = array_values($chain_list);
- return ds_json_encode(10000, '', array('chain_list' => $chain_list));
- }
- }
|