123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- class Pointcart extends MobileMember
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/pointcart.lang.php');
-
- if (config('ds_config.pointprod_isuse') != 1) {
- ds_json_encode(10001, lang('pointcart_unavailable'));
- }
- }
-
- public function cart_list()
- {
- $cart_goods = array();
- $pointcart_model = model('pointcart');
- $data = $pointcart_model->getPCartListAndAmount(array('pmember_id' => $this->member_info['member_id']));
- ds_json_encode(10000, lang('ds_common_op_succ'), array('pgoods_pointall' => $data['data']['cartgoods_pointall'], 'cart_array' => $data['data']['cartgoods_list']));
- return View::fetch($this->template_dir . 'pointcart_list');
- }
-
- public function cart_del()
- {
- $pcart_id = intval(input('param.pcart_id'));
- if ($pcart_id <= 0) {
- ds_json_encode(10001, lang('ds_common_del_fail'));
- }
- $pointcart_model = model('pointcart');
- $drop_state = $pointcart_model->delPointcartById($pcart_id, $this->member_info['member_id']);
- if ($drop_state) {
- ds_json_encode(10000, '');
- } else {
- ds_json_encode(10001, lang('ds_common_del_fail'));
- }
- }
-
- public function cart_edit_quantity()
- {
- $pcart_id = intval(input('param.pcart_id'));
- $quantity = intval(input('param.quantity'));
-
- $msg = lang('pointcart_cart_modcart_fail');
- if ($pcart_id <= 0 || $quantity <= 0) {
- ds_json_encode(10001, $msg);
- }
-
- $pointcart_model = model('pointcart');
- $cart_info = $pointcart_model->getPointcartInfo(array('pcart_id' => $pcart_id, 'pmember_id' => $this->member_info['member_id']));
- if (!$cart_info) {
- ds_json_encode(10001, $msg);
- }
-
- $data = $pointcart_model->checkExchange($cart_info['pgoods_id'], $quantity, $this->member_info['member_id']);
- if (!$data['state']) {
- ds_json_encode(10001, $data['msg']);
- }
- $prod_info = $data['data']['prod_info'];
- $quantity = $prod_info['quantity'];
- $cart_state = true;
-
- if ($cart_info['pgoods_choosenum'] != $quantity) {
- $cart_state = $pointcart_model->editPointcart(array('pcart_id' => $pcart_id, 'pmember_id' => $this->member_info['member_id']), array('pgoods_choosenum' => $quantity));
- }
- if ($cart_state) {
-
- $amount = $pointcart_model->getPointcartAmount($this->member_info['member_id']);
- ds_json_encode(10000, '', array('subtotal' => $prod_info['pointsamount'], 'amount' => $amount, 'quantity' => $quantity));
- }
- }
-
- public function add()
- {
- $pgid = intval(input('post.pgid'));
- $quantity = intval(input('post.quantity'));
- if ($pgid <= 0 || $quantity <= 0) {
- ds_json_encode(10001, lang('param_error'));
- }
- $pointcart_model = model('pointcart');
-
-
- $data = $pointcart_model->checkExchange($pgid, $quantity, $this->member_info['member_id']);
- if (!$data['state']) {
- ds_json_encode(10001, $data['msg']);
- }
-
- $check_cart = $pointcart_model->getPointcartInfo(array('pgoods_id' => $pgid, 'pmember_id' => $this->member_info['member_id']));
- if (!empty($check_cart)) {
- $cart_state = $pointcart_model->editPointcart(array('pcart_id' => $check_cart['pcart_id'], 'pmember_id' => $this->member_info['member_id']), array('pgoods_choosenum' => $quantity));
- ds_json_encode(10000, lang('ds_common_op_succ'), array('done' => 'ok1'));
- }
- $prod_info = $data['data']['prod_info'];
- $insert_arr = array();
- $insert_arr['pmember_id'] = $this->member_info['member_id'];
- $insert_arr['pgoods_id'] = $prod_info['pgoods_id'];
- $insert_arr['pgoods_name'] = $prod_info['pgoods_name'];
- $insert_arr['pgoods_points'] = $prod_info['pgoods_points'];
- $insert_arr['pgoods_choosenum'] = $prod_info['quantity'];
- $insert_arr['pgoods_image'] = $prod_info['pgoods_image_old'];
- $cart_state = $pointcart_model->addPointcart($insert_arr);
- if ($cart_state) {
- ds_json_encode(10000, lang('ds_common_op_succ'), array('done' => 'ok'));
- } else {
- ds_json_encode(10001, $data['msg']);
- }
- }
-
- public function step1()
- {
-
- $data = model('pointcart')->getCartGoodsList($this->member_info['member_id'], input('post.'));
- if (!$data['state']) {
- ds_json_encode(10001, $data['msg']);
- }
-
- $address_list = model('address')->getAddressList(array('member_id' => $this->member_info['member_id'], 'chain_id' => 0), 'address_is_default desc,address_id desc');
-
- ds_json_encode(10000, '', array('pointprod_arr' => $data['data'], 'address_info' => $address_list ? $address_list[0] : false));
- }
-
- public function step2()
- {
- $pointcart_model = model('pointcart');
-
- $data = $pointcart_model->getCartGoodsList($this->member_info['member_id'], input('post.'));
- if (!$data['state']) {
- ds_json_encode(10001, $data['msg']);
- }
- $pointprod_arr = $data['data'];
- unset($data);
-
- $data = $pointcart_model->checkPointEnough($pointprod_arr['pgoods_pointall'], $this->member_info['member_id']);
- if (!$data['state']) {
- ds_json_encode(10001, $data['msg']);
- }
- unset($data);
-
- $data = model('pointorder')->createOrder(input('post.'), $pointprod_arr, array('member_id' => $this->member_info['member_id'], 'member_name' => $this->member_info['member_name'], 'member_email' => $this->member_info['member_email']));
- if (!$data['state']) {
- ds_json_encode(10001, $data['msg']);
- }
- $order_id = $data['data']['order_id'];
- ds_json_encode(10000, '', array('pointprod_arr' => $order_id));
- }
-
- public function cart_count()
- {
- $pointcart_model = model('pointcart');
- $count = $pointcart_model->getPointcartCount($this->member_info['member_id']);
- $data['cart_count'] = $count;
- ds_json_encode(10000, '', $data);
- }
- }
|