/** * 增加退款退货 * * @param * @return int */ public function addRefundReturn($refund_array, $order = array(), $goods = array()) { if (!empty($order) && is_array($order)) { $refund_array['order_id'] = $order['order_id']; $refund_array['order_sn'] = $order['order_sn']; $refund_array['store_id'] = $order['store_id']; $refund_array['store_name'] = $order['store_name']; $refund_array['buyer_id'] = $order['buyer_id']; $refund_array['buyer_name'] = $order['buyer_name']; } if (!empty($goods) && is_array($goods)) { $refund_array['goods_id'] = $goods['goods_id']; $refund_array['order_goods_id'] = $goods['rec_id']; $refund_array['order_goods_type'] = $goods['goods_type']; $refund_array['goods_name'] = $goods['goods_name']; $refund_array['commis_rate'] = $goods['commis_rate']; $refund_array['goods_image'] = $goods['goods_image']; } $refund_array['refund_sn'] = $this->getRefundsn($refund_array['store_id']); $refund_id = $this->table('refund_return')->insert($refund_array); // 发送商家提醒 $param = array(); if (intval($refund_array['refund_type']) == 1) { // 退款 $param['code'] = 'refund'; } else { // 退货 $param['code'] = 'return'; } $param['store_id'] = $order['store_id']; $type = $refund_array['order_lock'] == 2 ? '售前' : '售后'; $param['param'] = array('type' => $type, 'refund_sn' => $refund_array['refund_sn']); QueueClient::push('sendStoreMsg', $param); return $refund_id; }
/** * 入列 * @param string $key * @param array $value */ public static function push($key, $value) { if (!C('queue.open')) { Logic('queue')->$key($value);return; } if (!is_object(self::$queuedb)) { self::$queuedb = new QueueDB(); } return self::$queuedb->push(serialize(array($key=>$value))); }
/** * 通知 */ public function indexOp() { $strat_time = strtotime("-30 day"); // 只通知最近30天的记录 $model_arrtivalnotice = Model('arrival_notice'); $count = $model_arrtivalnotice->getArrivalNoticeCount(array()); $times = ceil($count / $this->_num); if ($times == 0) { return false; } for ($i = 0; $i <= $times; $i++) { // 删除30天之前的记录 $model_arrtivalnotice->delArrivalNotice(array('an_addtime' => array('lt', $strat_time))); $notice_list = $model_arrtivalnotice->getArrivalNoticeList(array(), '*', $i . ',' . $this->_num); if (empty($notice_list)) { continue; } // 查询商品是否已经上架 $goodsid_array = array(); foreach ($notice_list as $val) { $goodsid_array[] = $val['goods_id']; } $goodsid_array = array_unique($goodsid_array); $goods_list = Model('goods')->getGoodsOnlineList(array('goods_id' => array('in', $goodsid_array), 'goods_storage' => array('gt', 0)), 'goods_id'); if (empty($goods_list)) { continue; } // 需要通知到货的商品 $goodsid_array = array(); foreach ($goods_list as $val) { $goodsid_array[] = $val['goods_id']; } // 根据商品id重新查询需要通知的列表 $notice_list = $model_arrtivalnotice->getArrivalNoticeList(array('goods_id' => array('in', $goodsid_array)), '*'); if (empty($notice_list)) { continue; } foreach ($notice_list as $val) { $param = array(); $param['code'] = 'arrival_notice'; $param['member_id'] = $val['member_id']; $param['param'] = array('goods_name' => $val['goods_name'], 'goods_url' => urlShop('goods', 'index', array('goods_id' => $val['goods_id']))); QueueClient::push('sendMemberMsg', $param); } // 清楚发送成功的数据 $model_arrtivalnotice->delArrivalNotice(array('goods_id' => array('in', $goodsid_array))); } }
/** * 回复咨询 */ public function consult_replyOp() { $model_mallconsult = Model('mall_consult'); if (chksubmit()) { $mc_id = intval($_POST['mc_id']); $reply_content = trim($_POST['reply_content']); if ($mc_id <= 0 || $reply_content == '') { showMessage(L('param_error')); } $update['is_reply'] = 1; $update['mc_reply'] = $reply_content; $update['mc_reply_time'] = TIMESTAMP; $update['admin_id'] = $this->admin_info['id']; $update['admin_name'] = $this->admin_info['name']; $result = $model_mallconsult->editMallConsult(array('mc_id' => $mc_id), $update); if ($result) { $consult_info = $model_mallconsult->getMallConsultInfo(array('mc_id' => $mc_id)); // 发送用户消息 $param = array(); $param['code'] = 'consult_mall_reply'; $param['member_id'] = $consult_info['member_id']; $param['param'] = array('consult_url' => urlShop('member_mallconsult', 'mallconsult_info', array('id' => $mc_id))); QueueClient::push('sendMemberMsg', $param); showMessage('回复成功', urlAdmin('mall_consult', 'index')); } else { showMessage('回复失败'); } } $id = intval($_GET['id']); if ($id <= 0) { showMessage(L('param_error')); } $consult_info = $model_mallconsult->getMallConsultDetail($id); Tpl::output('consult_info', $consult_info); Tpl::showpage('mall_consult.reply'); }
/** * 收货 * */ public function receiveOp() { $model_refund = Model('refund_return'); $model_trade = Model('trade'); $condition = array(); $condition['store_id'] = $_SESSION['store_id']; $condition['refund_id'] = intval($_GET['return_id']); $return_list = $model_refund->getReturnList($condition); $return = $return_list[0]; Tpl::output('return', $return); $return_delay = $model_trade->getMaxDay('return_delay'); //发货默认5天后才能选择没收到 $delay_time = time() - $return['delay_time'] - 60 * 60 * 24 * $return_delay; Tpl::output('return_delay', $return_delay); Tpl::output('return_confirm', $model_trade->getMaxDay('return_confirm')); //卖家不处理收货时按同意并弃货处理 Tpl::output('delay_time', $delay_time); if (chksubmit()) { if ($return['seller_state'] != '2' || $return['goods_state'] != '2') { //检查状态,防止页面刷新不及时造成数据错误 showDialog(Language::get('wrong_argument'), 'reload', 'error', 'CUR_DIALOG.close();'); } $refund_array = array(); if ($_POST['return_type'] == '3' && $delay_time > 0) { $refund_array['goods_state'] = '3'; } else { $refund_array['receive_time'] = time(); $refund_array['receive_message'] = '确认收货完成'; $refund_array['refund_state'] = '2'; //状态:1为处理中,2为待管理员处理,3为已完成 $refund_array['goods_state'] = '4'; } $state = $model_refund->editRefundReturn($condition, $refund_array); if ($state) { $this->recordSellerLog('退货确认收货,退货编号:' . $return['refund_sn']); // 发送买家消息 $param = array(); $param['code'] = 'refund_return_notice'; $param['member_id'] = $return['buyer_id']; $param['param'] = array('refund_url' => urlShop('member_return', 'view', array('return_id' => $return['refund_id'])), 'refund_sn' => $return['refund_sn']); QueueClient::push('sendMemberMsg', sendMemberMsg); showDialog(Language::get('nc_common_save_succ'), 'reload', 'succ', 'CUR_DIALOG.close();'); } else { showDialog(Language::get('nc_common_save_fail'), 'reload', 'error', 'CUR_DIALOG.close();'); } } $express_list = rkcache('express', true); if ($return['express_id'] > 0 && !empty($return['invoice_no'])) { Tpl::output('e_name', $express_list[$return['express_id']]['e_name']); Tpl::output('e_code', $express_list[$return['express_id']]['e_code']); } Tpl::showpage('store_return_receive', 'null_layout'); }
/** * 更新抢购购买人数和数量 */ private function _updateGroupBuy($goods_info) { if ($goods_info['ifgroupbuy'] && $goods_info['groupbuy_id']) { $groupbuy_info = array(); $groupbuy_info['groupbuy_id'] = $goods_info['groupbuy_id']; $groupbuy_info['quantity'] = $goods_info['quantity']; QueueClient::push('editGroupbuySaleCount', $groupbuy_info); } }
/** * 删除 * @param array $condition * @return bool * */ public function delXianshiGoods($condition) { $xianshi_goods_list = $this->getXianshiGoodsList($condition, null, '', 'goods_id'); $result = $this->where($condition)->delete(); if ($result) { if (!empty($xianshi_goods_list)) { foreach ($xianshi_goods_list as $val) { // 删除商品限时折扣缓存 $this->_dGoodsXianshiCache($val['goods_id']); // 插入对列 更新促销价格 QueueClient::push('updateGoodsPromotionPriceByGoodsId', $val['goods_id']); } } } return $result; }
/** * 变更预存款 * @param unknown $change_type * @param unknown $data * @throws Exception * @return unknown */ public function changePd($change_type, $data = array()) { $data_log = array(); $data_pd = array(); $data_msg = array(); $data_log['lg_member_id'] = $data['member_id']; $data_log['lg_member_name'] = $data['member_name']; $data_log['lg_add_time'] = TIMESTAMP; $data_log['lg_type'] = $change_type; $data_msg['time'] = date('Y-m-d H:i:s'); $data_msg['pd_url'] = urlShop('predeposit', 'pd_log_list'); switch ($change_type) { case 'order_pay': $data_log['lg_av_amount'] = -$data['amount']; $data_log['lg_desc'] = '下单,支付预存款,订单号: ' . $data['order_sn']; $data_pd['available_predeposit'] = array('exp', 'available_predeposit-' . $data['amount']); $data_msg['av_amount'] = -$data['amount']; $data_msg['freeze_amount'] = 0; $data_msg['desc'] = $data_log['lg_desc']; break; case 'order_freeze': $data_log['lg_av_amount'] = -$data['amount']; $data_log['lg_freeze_amount'] = $data['amount']; $data_log['lg_desc'] = '下单,冻结预存款,订单号: ' . $data['order_sn']; $data_pd['freeze_predeposit'] = array('exp', 'freeze_predeposit+' . $data['amount']); $data_pd['available_predeposit'] = array('exp', 'available_predeposit-' . $data['amount']); $data_msg['av_amount'] = -$data['amount']; $data_msg['freeze_amount'] = $data['amount']; $data_msg['desc'] = $data_log['lg_desc']; break; case 'order_cancel': $data_log['lg_av_amount'] = $data['amount']; $data_log['lg_freeze_amount'] = -$data['amount']; $data_log['lg_desc'] = '取消订单,解冻预存款,订单号: ' . $data['order_sn']; $data_pd['freeze_predeposit'] = array('exp', 'freeze_predeposit-' . $data['amount']); $data_pd['available_predeposit'] = array('exp', 'available_predeposit+' . $data['amount']); $data_msg['av_amount'] = $data['amount']; $data_msg['freeze_amount'] = -$data['amount']; $data_msg['desc'] = $data_log['lg_desc']; break; case 'order_comb_pay': $data_log['lg_freeze_amount'] = -$data['amount']; $data_log['lg_desc'] = '下单,支付被冻结的预存款,订单号: ' . $data['order_sn']; $data_pd['freeze_predeposit'] = array('exp', 'freeze_predeposit-' . $data['amount']); $data_msg['av_amount'] = 0; $data_msg['freeze_amount'] = $data['amount']; $data_msg['desc'] = $data_log['lg_desc']; break; case 'recharge': $data_log['lg_av_amount'] = $data['amount']; $data_log['lg_desc'] = '充值,充值单号: ' . $data['pdr_sn']; $data_log['lg_admin_name'] = $data['admin_name']; $data_pd['available_predeposit'] = array('exp', 'available_predeposit+' . $data['amount']); $data_msg['av_amount'] = $data['amount']; $data_msg['freeze_amount'] = 0; $data_msg['desc'] = $data_log['lg_desc']; break; case 'refund': $data_log['lg_av_amount'] = $data['amount']; $data_log['lg_desc'] = '确认退款,订单号: ' . $data['order_sn']; $data_pd['available_predeposit'] = array('exp', 'available_predeposit+' . $data['amount']); $data_msg['av_amount'] = $data['amount']; $data_msg['freeze_amount'] = 0; $data_msg['desc'] = $data_log['lg_desc']; break; case 'vr_refund': $data_log['lg_av_amount'] = $data['amount']; $data_log['lg_desc'] = '虚拟兑码退款成功,订单号: ' . $data['order_sn']; $data_pd['available_predeposit'] = array('exp', 'available_predeposit+' . $data['amount']); $data_msg['av_amount'] = $data['amount']; $data_msg['freeze_amount'] = 0; $data_msg['desc'] = $data_log['lg_desc']; break; case 'cash_apply': $data_log['lg_av_amount'] = -$data['amount']; $data_log['lg_freeze_amount'] = $data['amount']; $data_log['lg_desc'] = '申请提现,冻结预存款,提现单号: ' . $data['order_sn']; $data_pd['available_predeposit'] = array('exp', 'available_predeposit-' . $data['amount']); $data_pd['freeze_predeposit'] = array('exp', 'freeze_predeposit+' . $data['amount']); $data_msg['av_amount'] = -$data['amount']; $data_msg['freeze_amount'] = $data['amount']; $data_msg['desc'] = $data_log['lg_desc']; break; case 'cash_pay': $data_log['lg_freeze_amount'] = -$data['amount']; $data_log['lg_desc'] = '提现成功,提现单号: ' . $data['order_sn']; $data_log['lg_admin_name'] = $data['admin_name']; $data_pd['freeze_predeposit'] = array('exp', 'freeze_predeposit-' . $data['amount']); $data_msg['av_amount'] = 0; $data_msg['freeze_amount'] = -$data['amount']; $data_msg['desc'] = $data_log['lg_desc']; break; case 'cash_del': $data_log['lg_av_amount'] = $data['amount']; $data_log['lg_freeze_amount'] = -$data['amount']; $data_log['lg_desc'] = '取消提现申请,解冻预存款,提现单号: ' . $data['order_sn']; $data_log['lg_admin_name'] = $data['admin_name']; $data_pd['available_predeposit'] = array('exp', 'available_predeposit+' . $data['amount']); $data_pd['freeze_predeposit'] = array('exp', 'freeze_predeposit-' . $data['amount']); $data_msg['av_amount'] = $data['amount']; $data_msg['freeze_amount'] = -$data['amount']; $data_msg['desc'] = $data_log['lg_desc']; break; default: throw new Exception('参数错误'); break; } $update = Model('member')->editMember(array('member_id' => $data['member_id']), $data_pd); if (!$update) { throw new Exception('操作失败'); } $insert = $this->table('pd_log')->insert($data_log); if (!$insert) { throw new Exception('操作失败'); } // 支付成功发送买家消息 $param = array(); $param['code'] = 'predeposit_change'; $param['member_id'] = $data['member_id']; $data_msg['av_amount'] = ncPriceFormat($data_msg['av_amount']); $data_msg['freeze_amount'] = ncPriceFormat($data_msg['freeze_amount']); $param['param'] = $data_msg; QueueClient::push('sendMemberMsg', $param); return $insert; }
/** * 退货处理页 * */ public function editOp() { $model_refund = Model('refund_return'); $condition = array(); $condition['refund_id'] = intval($_GET['return_id']); $return_list = $model_refund->getReturnList($condition); $return = $return_list[0]; if (chksubmit()) { if ($return['refund_state'] != '2') { //检查状态,防止页面刷新不及时造成数据错误 showMessage(Language::get('nc_common_save_fail')); } $order_id = $return['order_id']; $refund_array = array(); $refund_array['admin_time'] = time(); $refund_array['refund_state'] = '3'; //状态:1为处理中,2为待管理员处理,3为已完成 $refund_array['admin_message'] = $_POST['admin_message']; $state = $model_refund->editOrderRefund($return); if ($state) { $model_refund->editRefundReturn($condition, $refund_array); $this->log('退货确认,退货编号' . $return['refund_sn']); // 发送买家消息 $param = array(); $param['code'] = 'refund_return_notice'; $param['member_id'] = $return['buyer_id']; $param['param'] = array('refund_url' => urlShop('return_id', 'view', array('return_id' => $return['refund_id'])), 'refund_sn' => $return['refund_sn']); QueueClient::push('sendMemberMsg', $param); showMessage(Language::get('nc_common_save_succ'), 'index.php?act=return&op=return_manage'); } else { showMessage(Language::get('nc_common_save_fail')); } } Tpl::output('return', $return); $info['buyer'] = array(); if (!empty($return['pic_info'])) { $info = unserialize($return['pic_info']); } Tpl::output('pic_list', $info['buyer']); Tpl::showpage('return.edit'); }
/** * 更改订单信息 * * @param unknown_type $data * @param unknown_type $condition */ public function editOrder($data, $condition, $limit = '') { $update = $this->table('order')->where($condition)->limit($limit)->update($data); if ($update) { //更新缓存 QueueClient::push('delOrderCountCache', $condition); } return $update; }
/** * 记录店铺费用 * * @param $cost_price 费用金额 * @param $cost_remark 费用备注 */ protected function recordStoreCost($cost_price, $cost_remark) { // 平台店铺不记录店铺费用 if (checkPlatformStore()) { return false; } $model_store_cost = Model('store_cost'); $param = array(); $param['cost_store_id'] = $_SESSION['store_id']; $param['cost_seller_id'] = $_SESSION['seller_id']; $param['cost_price'] = $cost_price; $param['cost_remark'] = $cost_remark; $param['cost_state'] = 0; $param['cost_time'] = TIMESTAMP; $model_store_cost->addStoreCost($param); // 发送店铺消息 $param = array(); $param['code'] = 'store_cost'; $param['store_id'] = $_SESSION['store_id']; $param['param'] = array('price' => $cost_price, 'seller_name' => $_SESSION['seller_name'], 'remark' => $cost_remark); QueueClient::push('sendStoreMsg', $param); }
/** * 提醒续费 */ public function remind_renewalOp() { $store_id = intval($_GET['store_id']); $store_info = Model('store')->getStoreInfoByID($store_id); if (!empty($store_info) && $store_info['store_end_time'] < TIMESTAMP + 864000 && cookie('remindRenewal' . $store_id) == null) { // 发送商家消息 $param = array(); $param['code'] = 'store_expire'; $param['store_id'] = intval($_GET['store_id']); $param['param'] = array(); QueueClient::push('sendStoreMsg', $param); setNcCookie('remindRenewal' . $store_id, 1, 86400 * 10); // 十天 showMessage('消息发送成功'); } showMessage('消息发送失败'); }
/** * 微信退款 v3-b12 * */ public function wxpayOp() { $result = array('state' => 'false', 'msg' => '参数错误,微信退款失败'); $refund_id = intval($_GET['refund_id']); $model_refund = Model('vr_refund'); $condition = array(); $condition['refund_id'] = $refund_id; $condition['refund_state'] = '1'; $detail_array = $model_refund->getDetailInfo($condition); //退款详细 if (!empty($detail_array) && in_array($detail_array['refund_code'], array('wxpay', 'wx_jsapi', 'wx_saoma'))) { $order = $model_refund->getPayDetailInfo($detail_array); //退款订单详细 $refund_amount = $order['pay_refund_amount']; //本次在线退款总金额 if ($refund_amount > 0) { $wxpay = $order['payment_config']; define('WXPAY_APPID', $wxpay['appid']); define('WXPAY_MCHID', $wxpay['mchid']); define('WXPAY_KEY', $wxpay['key']); $total_fee = $order['pay_amount'] * 100; //微信订单实际支付总金额(在线支付金额,单位为分) $refund_fee = $refund_amount * 100; //本次微信退款总金额(单位为分) $api_file = BASE_PATH . DS . 'api' . DS . 'refund' . DS . 'wxpay' . DS . 'WxPay.Api.php'; include $api_file; $input = new WxPayRefund(); $input->SetTransaction_id($order['trade_no']); //微信订单号 $input->SetTotal_fee($total_fee); $input->SetRefund_fee($refund_fee); $input->SetOut_refund_no($detail_array['batch_no']); //退款批次号 $input->SetOp_user_id(WxPayConfig::MCHID); $data = WxPayApi::refund($input); if (!empty($data) && $data['return_code'] == 'SUCCESS') { //请求结果 if ($data['result_code'] == 'SUCCESS') { //业务结果 $detail_array = array(); $detail_array['pay_amount'] = ncPriceFormat($data['refund_fee'] / 100); $detail_array['pay_time'] = time(); $model_refund->editDetail(array('refund_id' => $refund_id), $detail_array); $result['state'] = 'true'; $result['msg'] = '微信成功退款:' . $detail_array['pay_amount']; $refund = $model_refund->getRefundInfo(array('refund_id' => $refund_id)); $consume_array = array(); $consume_array['member_id'] = $refund['buyer_id']; $consume_array['member_name'] = $refund['buyer_name']; $consume_array['consume_amount'] = $detail_array['pay_amount']; $consume_array['consume_time'] = time(); $consume_array['consume_remark'] = '微信在线退款成功(到账有延迟),虚拟退款单号:' . $refund['refund_sn']; QueueClient::push('addConsume', $consume_array); } else { $result['msg'] = '微信退款错误,' . $data['err_code_des']; //错误描述 } } else { $result['msg'] = '微信接口错误,' . $data['return_msg']; //返回信息 } } } exit(json_encode($result)); }
/** * 生成所有店铺月订单出账单[虚拟订单] * * @param int $data */ private function _create_vr_order_bill($data){ $model_order = Model('vr_order'); $model_bill = Model('vr_bill'); $model_store = Model('store'); //批量插入order_bill表 $condition = array(); $condition['order_state'] = array('egt',ORDER_STATE_PAY); $condition['payment_time'] = array(array('egt',$data['os_start_date']),array('elt',$data['os_end_date']),'and'); //取出有最终成交订单的店铺ID数量(ID不重复) $order_info = $model_order->getOrderInfo($condition,'count(DISTINCT store_id) as store_count'); $store_count = $order_info['store_count']; //分批生成该月份的店铺空结算表,每批生成300个店铺 $insert = false; for ($i=0;$i<=$store_count;$i=$i+300){ $store_list = $model_order->getOrderList($condition,'','DISTINCT store_id','',"{$i},300"); if ($store_list){ //自动生成以月份为单位的空结算记录 $data_bill = array(); foreach($store_list as $store_info){ $data_bill['ob_no'] = $data['os_month'].$store_info['store_id']; $data_bill['ob_start_date'] = $data['os_start_date']; $data_bill['ob_end_date'] = $data['os_end_date']; $data_bill['os_month'] = $data['os_month']; $data_bill['ob_state'] = 0; $data_bill['ob_store_id'] = $store_info['store_id']; if (!$model_bill->getOrderBillInfo(array('ob_no'=>$data_bill['ob_no']))) { $insert = $model_bill->addOrderBill($data_bill); if (!$insert) { throw new Exception('生成账单['.$data_bill['ob_no'].']失败'); } //对已生成空账单进行销量、佣金统计 $update = $this->_calc_vr_order_bill($data_bill); if (!$update){ throw new Exception('更新账单['.$data_bill['ob_no'].']失败'); } // 发送店铺消息 $param = array(); $param['code'] = 'store_bill_affirm'; $param['store_id'] = $store_info['store_id']; $param['param'] = array( 'state_time' => date('Y-m-d H:i:s', $data_bill['ob_start_date']), 'end_time' => date('Y-m-d H:i:s', $data_bill['ob_end_date']), 'bill_no' => $data_bill['ob_no'] ); QueueClient::push('sendStoreMsg', $param); } } } } }
/** * 购物车更新商品数量 */ public function updateOp() { $cart_id = intval(abs($_GET['cart_id'])); $quantity = intval(abs($_GET['quantity'])); if (empty($cart_id) || empty($quantity)) { exit(json_encode(array('msg' => Language::get('cart_update_buy_fail', 'UTF-8')))); } $model_cart = Model('cart'); $model_goods = Model('goods'); $logic_buy_1 = logic('buy_1'); //存放返回信息 $return = array(); $cart_info = $model_cart->getCartInfo(array('cart_id' => $cart_id, 'buyer_id' => $_SESSION['member_id'])); if ($cart_info['bl_id'] == '0') { //普通商品 $goods_id = intval($cart_info['goods_id']); $goods_info = $logic_buy_1->getGoodsOnlineInfo($goods_id, $quantity); if (empty($goods_info)) { $return['state'] = 'invalid'; $return['msg'] = '商品已被下架'; $return['subtotal'] = 0; QueueClient::push('delCart', array('buyer_id' => $_SESSION['member_id'], 'cart_ids' => array($cart_id))); exit(json_encode($return)); } //抢购 $logic_buy_1->getGroupbuyInfo($goods_info); //限时折扣 $logic_buy_1->getXianshiInfo($goods_info, $quantity); $quantity = $goods_info['goods_num']; if (intval($goods_info['goods_storage']) < $quantity) { $return['state'] = 'shortage'; $return['msg'] = '库存不足'; $return['goods_num'] = $goods_info['goods_num']; $return['goods_price'] = $goods_info['goods_price']; $return['subtotal'] = $goods_info['goods_price'] * $quantity; $model_cart->editCart(array('goods_num' => $goods_info['goods_storage']), array('cart_id' => $cart_id, 'buyer_id' => $_SESSION['member_id'])); exit(json_encode($return)); } } else { //优惠套装商品 $model_bl = Model('p_bundling'); $bl_goods_list = $model_bl->getBundlingGoodsList(array('bl_id' => $cart_info['bl_id'])); $goods_id_array = array(); foreach ($bl_goods_list as $goods) { $goods_id_array[] = $goods['goods_id']; } $goods_list = $model_goods->getGoodsOnlineListAndPromotionByIdArray($goods_id_array); //如果其中有商品下架,删除 if (count($goods_list) != count($goods_id_array)) { $return['state'] = 'invalid'; $return['msg'] = '该优惠套装已经无效,建议您购买单个商品'; $return['subtotal'] = 0; QueueClient::push('delCart', array('buyer_id' => $_SESSION['member_id'], 'cart_ids' => array($cart_id))); exit(json_encode($return)); } //如果有商品库存不足,更新购买数量到目前最大库存 foreach ($goods_list as $goods_info) { if ($quantity > $goods_info['goods_storage']) { $return['state'] = 'shortage'; $return['msg'] = '该优惠套装部分商品库存不足,建议您降低购买数量或购买库存足够的单个商品'; $return['goods_num'] = $goods_info['goods_storage']; $return['goods_price'] = $cart_info['goods_price']; $return['subtotal'] = $cart_info['goods_price'] * $quantity; $model_cart->editCart(array('goods_num' => $goods_info['goods_storage']), array('cart_id' => $cart_id, 'buyer_id' => $_SESSION['member_id'])); exit(json_encode($return)); break; } } $goods_info['goods_price'] = $cart_info['goods_price']; } $data = array(); $data['goods_num'] = $quantity; $data['goods_price'] = $goods_info['goods_price']; $update = $model_cart->editCart($data, array('cart_id' => $cart_id, 'buyer_id' => $_SESSION['member_id'])); if ($update) { $return = array(); $return['state'] = 'true'; $return['subtotal'] = $goods_info['goods_price'] * $quantity; $return['goods_price'] = $goods_info['goods_price']; $return['goods_num'] = $quantity; } else { $return = array('msg' => Language::get('cart_update_buy_fail', 'UTF-8')); } exit(json_encode($return)); }
/** * 购物车、直接购买第二步:保存订单入库,产生订单号,开始选择支付方式 * */ public function buyStep2($post, $member_id, $member_name, $member_email) { $model_cart = Model('cart'); //取得商品ID和购买数量 $input_buy_items = $this->_parseItems($post['cart_id']); //验证收货地址 $input_address_id = intval($post['address_id']); if ($input_address_id <= 0) { return array('error' => '请选择收货地址'); } else { $input_address_info = Model('address')->getAddressInfo(array('address_id' => $input_address_id)); if ($input_address_info['member_id'] != $member_id) { return array('error' => '请选择收货地址'); } } //收货地址城市编号 $input_city_id = intval($input_address_info['city_id']); //是否开增值税发票 $input_if_vat = $this->buyDecrypt($post['vat_hash'], $member_id); if (!in_array($input_if_vat, array('allow_vat', 'deny_vat'))) { return array('error' => '订单保存出现异常,请重试'); } $input_if_vat = $input_if_vat == 'allow_vat' ? true : false; //是否支持货到付款 $input_if_offpay = $this->buyDecrypt($post['offpay_hash'], $member_id); if (!in_array($input_if_offpay, array('allow_offpay', 'deny_offpay'))) { return array('error' => '订单保存出现异常,请重试'); } $input_if_offpay = $input_if_offpay == 'allow_offpay' ? true : false; //付款方式:在线支付/货到付款(online/offline) if (!in_array($post['pay_name'], array('online', 'offline'))) { return array('error' => '付款方式错误,请重新选择'); } $input_pay_name = $post['pay_name']; //验证发票信息 if (!empty($post['invoice_id'])) { $input_invoice_id = intval($post['invoice_id']); if ($input_invoice_id > 0) { $input_invoice_info = Model('invoice')->getinvInfo(array('inv_id' => $input_invoice_id)); if ($input_invoice_info['member_id'] != $member_id) { return array('error' => '请正确填写发票信息'); } } } //验证代金券 $input_voucher_list = array(); if (is_array($post['voucher'])) { foreach ($post['voucher'] as $store_id => $voucher) { if (preg_match_all('/^(\\d+)\\|(\\d+)\\|([\\d.]+)$/', $voucher, $matchs)) { if (floatval($matchs[3][0]) > 0) { $input_voucher_list[$store_id]['voucher_t_id'] = $matchs[1][0]; $input_voucher_list[$store_id]['voucher_price'] = $matchs[3][0]; } } } } if ($post['ifcart']) { //取购物车列表 $condition = array('cart_id' => array('in', array_keys($input_buy_items)), 'buyer_id' => $member_id); $cart_list = $model_cart->listCart('db', $condition); //取商品最新的在售信息 $cart_list = $model_cart->getOnlineCartList($cart_list); //得到限时折扣信息 $cart_list = $model_cart->getXianshiCartList($cart_list); //得到优惠套装状态,并取得组合套装商品列表 $cart_list = $model_cart->getBundlingCartList($cart_list); //到得商品列表 $goods_list = $model_cart->getGoodsList($cart_list); //购物车列表以店铺ID分组显示 $store_cart_list = $model_cart->getStoreCartList($cart_list); } else { //来源于直接购买 //取得购买的商品ID和购买数量,只有有一个下标 ,只会循环一次 foreach ($input_buy_items as $goods_id => $quantity) { break; } //取得商品最新在售信息 $goods_info = $model_cart->getGoodsOnlineInfo($goods_id, $quantity); if (empty($goods_info)) { return array('error' => '商品不存在'); } //判断是不是正在抢购中,如果是则按抢购价格计算,购买数量若超过抢购规定的上限,则按抢购上限计算 $goods_info = $model_cart->getGroupbuyInfo($goods_info); //如果未进行抢购,则再判断是否限时折扣中 if (!$goods_info['ifgroupbuy']) { $goods_info = $model_cart->getXianshiInfo($goods_info, $quantity); } else { //这里记录一下抢购数量,订单完成后需要更新一下抢购表信息 $groupbuy_info = array(); $groupbuy_info['groupbuy_id'] = $goods_info['groupbuy_id']; $groupbuy_info['quantity'] = $quantity; } //转成多维数组,方便统一使用购物车方法与模板 $store_cart_list = array(); $goods_list = array(); $goods_list[0] = $store_cart_list[$goods_info['store_id']][0] = $goods_info; } //商品金额计算(分别对每个商品/优惠套装小计、每个店铺小计) list($store_cart_list, $store_goods_total) = $model_cart->calcCartList($store_cart_list); //取得店铺优惠 - 满即送(赠品列表,店铺满送规则列表) list($store_premiums_list, $store_mansong_rule_list) = $model_cart->getMansongRuleCartListByTotal($store_goods_total); //重新计算店铺扣除满即送后商品实际支付金额 $store_final_goods_total = $model_cart->reCalcGoodsTotal($store_goods_total, $store_mansong_rule_list, 'mansong'); //得到有效的代金券 $input_voucher_list = $model_cart->reParseVoucherList($input_voucher_list, $store_goods_total, $member_id); //重新计算店铺扣除优惠券送商品实际支付金额 $store_final_goods_total = $model_cart->reCalcGoodsTotal($store_final_goods_total, $input_voucher_list, 'voucher'); //计算每个店铺(所有店铺级优惠活动)总共优惠多少 $store_promotion_total = $this->getStorePromotionTotal($store_goods_total, $store_final_goods_total); //计算每个店铺运费 list($need_calc_sid_list, $cancel_calc_sid_list) = $this->getStoreFreightDescList($store_final_goods_total); $freight_list = $this->getStoreFreightList($goods_list, array_keys($cancel_calc_sid_list)); $store_freight_total = $this->calcStoreFreight($freight_list, $input_city_id); //计算店铺最终订单实际支付金额(加上运费) $store_final_order_total = $model_cart->reCalcGoodsTotal($store_final_goods_total, $store_freight_total, 'freight'); //计算店铺分类佣金 $store_gc_id_commis_rate_list = $this->getStoreGcidCommisRateList($goods_list); //将赠品追加到购买列表(如果库存不足,则不送赠品) $append_premiums_to_cart_list = $this->appendPremiumsToCartList($store_cart_list, $store_premiums_list, $store_mansong_rule_list, $member_id); if (!empty($append_premiums_to_cart_list['error'])) { return array('error' => $append_premiums_to_cart_list['error']); } else { list($store_cart_list, $goods_buy_quantity, $store_mansong_rule_list) = $append_premiums_to_cart_list; } //整理已经得出的固定数据,准备下单 $input = array(); $input['pay_name'] = $input_pay_name; $input['if_offpay'] = $input_if_offpay; $input['if_vat'] = $input_if_vat; $input['pay_message'] = $post['pay_message']; $input['address_info'] = $input_address_info; $input['invoice_info'] = $input_invoice_info; $input['voucher_list'] = $input_voucher_list; $input['store_goods_total'] = $store_goods_total; $input['store_final_order_total'] = $store_final_order_total; $input['store_freight_total'] = $store_freight_total; $input['store_promotion_total'] = $store_promotion_total; $input['store_gc_id_commis_rate_list'] = $store_gc_id_commis_rate_list; $input['store_mansong_rule_list'] = $store_mansong_rule_list; $input['store_cart_list'] = $store_cart_list; try { //开始事务 $model_cart->beginTransaction(); //生成订单 list($pay_sn, $order_list) = $this->createOrder($input, $member_id, $member_name, $member_email); //记录订单日志 $this->addOrderLog($order_list); //变更库存和销量 $this->updateGoodsStorageNum($goods_buy_quantity); //使用预存款支付 $this->pdPay($order_list, $post, $member_id, $member_name); //提交事务 $model_cart->commit(); } catch (Exception $e) { //回滚事务 $model_cart->rollback(); return array('error' => $e->getMessage()); } //更新使用的代金券状态 if (!empty($input_voucher_list) && is_array($input_voucher_list)) { QueueClient::push('editVoucherState', $input_voucher_list); } //更新抢购购买人数和数量 if (!empty($groupbuy_info) && is_array($groupbuy_info)) { QueueClient::push('editGroupbuySaleCount', $groupbuy_info); } //更新收货人所在省份 QueueClient::push('editReciverProid', array('order_ids' => array_keys($order_list), 'area_id' => $input_city_id)); //删除购物车中的商品 if ($post['ifcart']) { $model_cart->delCart('db', array('buyer_id' => $member_id, 'cart_id' => array('in', array_keys($input_buy_items)))); // QueueClient::push('delCart', array('buyer_id'=>$member_id,'cart_ids'=>array_keys($input_buy_items))); } return array('pay_sn' => $pay_sn); }
/** * 过期抢购修改状态,解锁对应商品 */ public function editExpireGroupbuy($condition) { $condition['end_time'] = array('lt', TIMESTAMP); $condition['state'] = array('in', array(self::GROUPBUY_STATE_REVIEW, self::GROUPBUY_STATE_NORMAL)); $expire_groupbuy_list = $this->getGroupbuyExtendList($condition, null); if (!empty($expire_groupbuy_list)) { $goodscommonid_array = array(); foreach ($expire_groupbuy_list as $val) { $goodscommonid_array[] = $val['goods_commonid']; } // 更新商品促销价格,需要考虑抢购是否在进行中 QueueClient::push('updateGoodsPromotionPriceByGoodsCommonId', $goodscommonid_array); } $groupbuy_id_string = ''; if (!empty($expire_groupbuy_list)) { foreach ($expire_groupbuy_list as $value) { $groupbuy_id_string .= $value['groupbuy_id'] . ','; } } if ($groupbuy_id_string != '') { $update = array(); $update['state'] = self::GROUPBUY_STATE_CLOSE; $condition = array(); $condition['groupbuy_id'] = array('in', rtrim($groupbuy_id_string, ',')); $result = $this->editGroupbuy($update, $condition); if ($result) { foreach ($expire_groupbuy_list as $value) { $this->_unlockGoods($value['goods_commonid']); } } } return true; }
/** * 过期修改状态 */ public function editExpireXianshi($condition) { $condition['end_time'] = array('lt', TIMESTAMP); // 更新商品促销价格 $xianshigoods_list = Model('p_xianshi_goods')->getXianshiGoodsList($condition); if (!empty($xianshigoods_list)) { $goodsid_array = array(); foreach ($xianshigoods_list as $val) { $goodsid_array[] = $val['goods_id']; } // 更新商品促销价格,需要考虑抢购是否在进行中 QueueClient::push('updateGoodsPromotionPriceByGoodsId', $goodsid_array); } $condition['state'] = self::XIANSHI_STATE_NORMAL; $updata = array(); $update['state'] = self::XIANSHI_STATE_CLOSE; $this->editXianshi($update, $condition); return true; }
/** * 取件通知 */ public function arrive_pointOp() { $order_id = intval($_GET['order_id']); if ($order_id <= 0) { showDialog(L('wrong_argument')); } $pickup_code = $this->createPickupCode(); // 更新提货订单表数据 $update = array(); $update['dlyo_pickup_code'] = $pickup_code; Model('delivery_order')->editDeliveryOrderArrive($update, array('order_id' => $order_id, 'dlyp_id' => $_SESSION['dlyp_id'])); // 更新订单扩展表数据 Model('order')->editOrderCommon($update, array('order_id' => $order_id)); // 发送短信提醒 QueueClient::push('sendPickupcode', array('pickup_code' => $pickup_code, 'order_id' => $order_id)); showDialog('操作成功', 'reload', 'succ'); }
/** * 账单付款 * */ public function bill_payOp() { if (!preg_match('/^20\\d{5,12}$/', $_GET['ob_no'])) { showMessage('参数错误', '', 'html', 'error'); } $model_bill = Model('vr_bill'); $condition = array(); $condition['ob_no'] = $_GET['ob_no']; $condition['ob_state'] = BILL_STATE_SYSTEM_CHECK; $bill_info = $model_bill->getOrderBillInfo($condition); if (!$bill_info) { showMessage('参数错误', '', 'html', 'error'); } if (chksubmit()) { if (!preg_match('/^20\\d{2}-\\d{2}-\\d{2}$/', $_POST['pay_date'])) { showMessage('参数错误', '', 'html', 'error'); } $input = array(); $input['ob_pay_content'] = $_POST['pay_content']; $input['ob_pay_date'] = strtotime($_POST['pay_date']); $input['ob_state'] = BILL_STATE_SUCCESS; $update = $model_bill->editOrderBill($input, $condition); if ($update) { // 发送店铺消息 $param = array(); $param['code'] = 'store_bill_gathering'; $param['store_id'] = $bill_info['ob_store_id']; $param['param'] = array('bill_no' => $bill_info['ob_no']); QueueClient::push('sendStoreMsg', $param); $this->log('账单付款,账单号:' . $_GET['ob_no'], 1); showMessage('保存成功', 'index.php?act=vr_bill&op=show_statis&os_month=' . $bill_info['os_month']); } else { $this->log('账单付款,账单号:' . $_GET['ob_no'], 1); showMessage('保存失败', '', 'html', 'error'); } } else { Tpl::showpage('vr_bill.pay'); } }
/** * 收到货款 * @param array $order_info * @param string $role 操作角色 buyer、seller、admin、system 分别代表买家、商家、管理员、系统 * @param string $user 操作人 * @return array */ public function changeOrderReceivePay($order_list, $role, $user = '', $post = array()) { $model_order = Model('order'); try { $model_order->beginTransaction(); $data = array(); $data['api_pay_state'] = 1; $update = $model_order->editOrderPay($data, array('pay_sn' => $order_list[0]['pay_sn'])); //$update = $model_order->editOrderPay($data,array('pay_sn'=>$order_info['pay_sn'])); if (!$update) { throw new Exception('更新支付单状态失败'); } $model_pd = Model('predeposit'); foreach ($order_list as $order_info) { $order_id = $order_info['order_id']; if ($order_info['order_state'] != ORDER_STATE_NEW) { continue; } //下单,支付被冻结的充值卡 $rcb_amount = floatval($order_info['rcb_amount']); if ($rcb_amount > 0) { $data_pd = array(); $data_pd['member_id'] = $order_info['buyer_id']; $data_pd['member_name'] = $order_info['buyer_name']; $data_pd['amount'] = $rcb_amount; $data_pd['order_sn'] = $order_info['order_sn']; $model_pd->changeRcb('order_comb_pay', $data_pd); } //下单,支付被冻结的预存款 $pd_amount = floatval($order_info['pd_amount']); if ($pd_amount > 0) { $data_pd = array(); $data_pd['member_id'] = $order_info['buyer_id']; $data_pd['member_name'] = $order_info['buyer_name']; $data_pd['amount'] = $pd_amount; $data_pd['order_sn'] = $order_info['order_sn']; $model_pd->changePd('order_comb_pay', $data_pd); } } //更新订单状态 $update_order = array(); $update_order['order_state'] = ORDER_STATE_PAY; $update_order['payment_time'] = $post['payment_time'] ? strtotime($post['payment_time']) : TIMESTAMP; $update_order['payment_code'] = $post['payment_code']; $update = $model_order->editOrder($update_order, array('pay_sn' => $order_info['pay_sn'], 'order_state' => ORDER_STATE_NEW)); if (!$update) { throw new Exception('操作失败'); } $model_order->commit(); } catch (Exception $e) { $model_order->rollback(); return callback(false, $e->getMessage()); } foreach ($order_list as $order_info) { //防止重复发送消息 v 3 - 3 3 h a o . c o m if ($order_info['order_state'] != ORDER_STATE_NEW) { continue; } $order_id = $order_info['order_id']; // 支付成功发送买家消息 $param = array(); $param['code'] = 'order_payment_success'; $param['member_id'] = $order_info['buyer_id']; $param['param'] = array('order_sn' => $order_info['order_sn'], 'order_url' => urlShop('member_order', 'show_order', array('order_id' => $order_info['order_id']))); QueueClient::push('sendMemberMsg', $param); // 支付成功发送店铺消息 $param = array(); $param['code'] = 'new_order'; $param['store_id'] = $order_info['store_id']; $param['param'] = array('order_sn' => $order_info['order_sn']); QueueClient::push('sendStoreMsg', $param); //添加订单日志 $data = array(); $data['order_id'] = $order_id; $data['log_role'] = $role; $data['log_user'] = $user; $data['log_msg'] = '收到了货款 ( 支付平台交易号 : ' . $post['trade_no'] . ' )'; $data['log_orderstate'] = ORDER_STATE_PAY; $model_order->addOrderLog($data); } return callback(true, '操作成功'); }
/** * 保存商品(商品发布第二步使用) */ public function save_goodsOp() { if (chksubmit()) { // 验证表单 $obj_validate = new Validate(); $obj_validate->validateparam = array(array("input" => $_POST["g_name"], "require" => "true", "message" => L('store_goods_index_goods_name_null')), array("input" => $_POST["g_price"], "require" => "true", "validator" => "Double", "message" => L('store_goods_index_goods_price_null'))); $error = $obj_validate->validate(); if ($error != '') { showMessage(L('error') . $error, urlShop('seller_center'), 'html', 'error'); } $model_goods = Model('goods'); $model_type = Model('type'); // 分类信息 $goods_class = Model('goods_class')->getGoodsClassLineForTag(intval($_POST['cate_id'])); $common_array = array(); $common_array['goods_name'] = $_POST['g_name']; $common_array['goods_jingle'] = $_POST['g_jingle']; $common_array['gc_id'] = intval($_POST['cate_id']); $common_array['gc_id_1'] = intval($goods_class['gc_id_1']); $common_array['gc_id_2'] = intval($goods_class['gc_id_2']); $common_array['gc_id_3'] = intval($goods_class['gc_id_3']); $common_array['gc_name'] = $_POST['cate_name']; $common_array['brand_id'] = $_POST['b_id']; $common_array['brand_name'] = $_POST['b_name']; $common_array['type_id'] = intval($_POST['type_id']); $common_array['goods_image'] = $_POST['image_path']; $common_array['goods_price'] = floatval($_POST['g_price']); $common_array['goods_marketprice'] = floatval($_POST['g_marketprice']); $common_array['goods_costprice'] = floatval($_POST['g_costprice']); $common_array['goods_discount'] = floatval($_POST['g_discount']); $common_array['goods_serial'] = $_POST['g_serial']; $common_array['goods_storage_alarm'] = intval($_POST['g_alarm']); $common_array['goods_attr'] = serialize($_POST['attr']); $common_array['goods_body'] = $_POST['g_body']; // 序列化保存手机端商品描述数据 if ($_POST['m_body'] != '') { $_POST['m_body'] = str_replace('"', '"', $_POST['m_body']); $_POST['m_body'] = json_decode($_POST['m_body'], true); if (!empty($_POST['m_body'])) { $_POST['m_body'] = serialize($_POST['m_body']); } else { $_POST['m_body'] = ''; } } $common_array['mobile_body'] = $_POST['m_body']; $common_array['goods_commend'] = intval($_POST['g_commend']); $common_array['goods_state'] = $this->store_info['store_state'] != 1 ? 0 : intval($_POST['g_state']); // 店铺关闭时,商品下架 $common_array['goods_addtime'] = TIMESTAMP; $common_array['goods_selltime'] = strtotime($_POST['starttime']) + intval($_POST['starttime_H']) * 3600 + intval($_POST['starttime_i']) * 60; $common_array['goods_verify'] = C('goods_verify') == 1 ? 10 : 1; $common_array['store_id'] = $_SESSION['store_id']; $common_array['store_name'] = $_SESSION['store_name']; $common_array['spec_name'] = is_array($_POST['spec']) ? serialize($_POST['sp_name']) : serialize(null); $common_array['spec_value'] = is_array($_POST['spec']) ? serialize($_POST['sp_val']) : serialize(null); $common_array['goods_vat'] = intval($_POST['g_vat']); $common_array['areaid_1'] = intval($_POST['province_id']); $common_array['areaid_2'] = intval($_POST['city_id']); $common_array['transport_id'] = $_POST['freight'] == '0' ? '0' : intval($_POST['transport_id']); // 运费模板 $common_array['transport_title'] = $_POST['transport_title']; $common_array['goods_freight'] = floatval($_POST['g_freight']); //查询店铺商品分类 $goods_stcids_arr = array(); if (!empty($_POST['sgcate_id'])) { $sgcate_id_arr = array(); foreach ($_POST['sgcate_id'] as $k => $v) { $sgcate_id_arr[] = intval($v); } $sgcate_id_arr = array_unique($sgcate_id_arr); $store_goods_class = Model('store_goods_class')->getStoreGoodsClassList(array('store_id' => $_SESSION['store_id'], 'stc_id' => array('in', $sgcate_id_arr), 'stc_state' => '1')); if (!empty($store_goods_class)) { foreach ($store_goods_class as $k => $v) { if ($v['stc_id'] > 0) { $goods_stcids_arr[] = $v['stc_id']; } if ($v['stc_parent_id'] > 0) { $goods_stcids_arr[] = $v['stc_parent_id']; } } $goods_stcids_arr = array_unique($goods_stcids_arr); sort($goods_stcids_arr); } } if (empty($goods_stcids_arr)) { $common_array['goods_stcids'] = ''; } else { $common_array['goods_stcids'] = ',' . implode(',', $goods_stcids_arr) . ','; // 首尾需要加, } $common_array['plateid_top'] = intval($_POST['plate_top']) > 0 ? intval($_POST['plate_top']) : ''; $common_array['plateid_bottom'] = intval($_POST['plate_bottom']) > 0 ? intval($_POST['plate_bottom']) : ''; $common_array['is_virtual'] = intval($_POST['is_gv']); $common_array['virtual_indate'] = $_POST['g_vindate'] != '' ? strtotime($_POST['g_vindate']) + 24 * 60 * 60 - 1 : 0; // 当天的最后一秒结束 $common_array['virtual_limit'] = intval($_POST['g_vlimit']) > 10 || intval($_POST['g_vlimit']) < 0 ? 10 : intval($_POST['g_vlimit']); $common_array['virtual_invalid_refund'] = intval($_POST['g_vinvalidrefund']); $common_array['is_fcode'] = intval($_POST['is_fc']); $common_array['is_appoint'] = intval($_POST['is_appoint']); // 只有库存为零的商品可以预约 $common_array['appoint_satedate'] = $common_array['is_appoint'] == 1 ? strtotime($_POST['g_saledate']) : ''; // 预约商品的销售时间 $common_array['is_presell'] = $common_array['goods_state'] == 1 ? intval($_POST['is_presell']) : 0; // 只有出售中的商品可以预售 $common_array['presell_deliverdate'] = $common_array['is_presell'] == 1 ? strtotime($_POST['g_deliverdate']) : ''; // 预售商品的发货时间 $common_array['is_own_shop'] = in_array($_SESSION['store_id'], model('store')->getOwnShopIds()) ? 1 : 0; // 保存数据 $common_id = $model_goods->addGoodsCommon($common_array); if ($common_id) { // 生成的商品id(SKU) $goodsid_array = array(); require_once BASE_RESOURCE_PATH . DS . 'phpqrcode' . DS . 'index.php'; $PhpQRCode = new PhpQRCode(); $PhpQRCode->set('pngTempDir', BASE_UPLOAD_PATH . DS . ATTACH_STORE . DS . $_SESSION['store_id'] . DS); // 商品规格 if (is_array($_POST['spec'])) { foreach ($_POST['spec'] as $value) { $goods = array(); $goods['goods_commonid'] = $common_id; $goods['goods_name'] = $common_array['goods_name'] . ' ' . implode(' ', $value['sp_value']); $goods['goods_jingle'] = $common_array['goods_jingle']; $goods['store_id'] = $common_array['store_id']; $goods['store_name'] = $_SESSION['store_name']; $goods['gc_id'] = $common_array['gc_id']; $goods['gc_id_1'] = $common_array['gc_id_1']; $goods['gc_id_2'] = $common_array['gc_id_2']; $goods['gc_id_3'] = $common_array['gc_id_3']; $goods['brand_id'] = $common_array['brand_id']; $goods['goods_price'] = $value['price']; $goods['goods_promotion_price'] = $value['price']; $goods['goods_marketprice'] = $value['marketprice'] == 0 ? $common_array['goods_marketprice'] : $value['marketprice']; $goods['goods_serial'] = $value['sku']; $goods['goods_storage_alarm'] = intval($value['alarm']); $goods['goods_spec'] = serialize($value['sp_value']); $goods['goods_storage'] = $value['stock']; $goods['goods_image'] = $common_array['goods_image']; $goods['goods_state'] = $common_array['goods_state']; $goods['goods_verify'] = $common_array['goods_verify']; $goods['goods_addtime'] = TIMESTAMP; $goods['goods_edittime'] = TIMESTAMP; $goods['areaid_1'] = $common_array['areaid_1']; $goods['areaid_2'] = $common_array['areaid_2']; $goods['color_id'] = intval($value['color']); $goods['transport_id'] = $common_array['transport_id']; $goods['goods_freight'] = $common_array['goods_freight']; $goods['goods_vat'] = $common_array['goods_vat']; $goods['goods_commend'] = $common_array['goods_commend']; $goods['goods_stcids'] = $common_array['goods_stcids']; $goods['is_virtual'] = $common_array['is_virtual']; $goods['virtual_indate'] = $common_array['virtual_indate']; $goods['virtual_limit'] = $common_array['virtual_limit']; $goods['virtual_invalid_refund'] = $common_array['virtual_invalid_refund']; $goods['is_fcode'] = $common_array['is_fcode']; $goods['is_appoint'] = $common_array['is_appoint']; $goods['is_presell'] = $common_array['is_presell']; $goods['is_own_shop'] = $common_array['is_own_shop']; $goods_id = $model_goods->addGoods($goods); $model_type->addGoodsType($goods_id, $common_id, array('cate_id' => $_POST['cate_id'], 'type_id' => $_POST['type_id'], 'attr' => $_POST['attr'])); $goodsid_array[] = $goods_id; // 生成商品二维码 $PhpQRCode->set('date', WAP_SITE_URL . '/tmpl/product_detail.html?goods_id=' . $goods_id); $PhpQRCode->set('pngTempName', $goods_id . '.png'); $PhpQRCode->init(); } } else { $goods = array(); $goods['goods_commonid'] = $common_id; $goods['goods_name'] = $common_array['goods_name']; $goods['goods_jingle'] = $common_array['goods_jingle']; $goods['store_id'] = $common_array['store_id']; $goods['store_name'] = $_SESSION['store_name']; $goods['gc_id'] = $common_array['gc_id']; $goods['gc_id_1'] = $common_array['gc_id_1']; $goods['gc_id_2'] = $common_array['gc_id_2']; $goods['gc_id_3'] = $common_array['gc_id_3']; $goods['brand_id'] = $common_array['brand_id']; $goods['goods_price'] = $common_array['goods_price']; $goods['goods_promotion_price'] = $common_array['goods_price']; $goods['goods_marketprice'] = $common_array['goods_marketprice']; $goods['goods_serial'] = $common_array['goods_serial']; $goods['goods_storage_alarm'] = $common_array['goods_storage_alarm']; $goods['goods_spec'] = serialize(null); $goods['goods_storage'] = intval($_POST['g_storage']); $goods['goods_image'] = $common_array['goods_image']; $goods['goods_state'] = $common_array['goods_state']; $goods['goods_verify'] = $common_array['goods_verify']; $goods['goods_addtime'] = TIMESTAMP; $goods['goods_edittime'] = TIMESTAMP; $goods['areaid_1'] = $common_array['areaid_1']; $goods['areaid_2'] = $common_array['areaid_2']; $goods['color_id'] = 0; $goods['transport_id'] = $common_array['transport_id']; $goods['goods_freight'] = $common_array['goods_freight']; $goods['goods_vat'] = $common_array['goods_vat']; $goods['goods_commend'] = $common_array['goods_commend']; $goods['goods_stcids'] = $common_array['goods_stcids']; $goods['is_virtual'] = $common_array['is_virtual']; $goods['virtual_indate'] = $common_array['virtual_indate']; $goods['virtual_limit'] = $common_array['virtual_limit']; $goods['virtual_invalid_refund'] = $common_array['virtual_invalid_refund']; $goods['is_fcode'] = $common_array['is_fcode']; $goods['is_appoint'] = $common_array['is_appoint']; $goods['is_presell'] = $common_array['is_presell']; $goods['is_own_shop'] = $common_array['is_own_shop']; $goods_id = $model_goods->addGoods($goods); $model_type->addGoodsType($goods_id, $common_id, array('cate_id' => $_POST['cate_id'], 'type_id' => $_POST['type_id'], 'attr' => $_POST['attr'])); $goodsid_array[] = $goods_id; } // 生成商品二维码 if (!empty($goodsid_array)) { //QueueClient::push('createGoodsQRCode', array('store_id' => $_SESSION['store_id'], 'goodsid_array' => $goodsid_array)); $PhpQRCode->set('date', WAP_SITE_URL . '/tmpl/product_detail.html?goods_id=' . $goods_id); $PhpQRCode->set('pngTempName', $goods_id . '.png'); $PhpQRCode->init(); } // 商品加入上架队列 if (isset($_POST['starttime'])) { $selltime = strtotime($_POST['starttime']) + intval($_POST['starttime_H']) * 3600 + intval($_POST['starttime_i']) * 60; if ($selltime > TIMESTAMP) { $this->addcron(array('exetime' => $selltime, 'exeid' => $common_id, 'type' => 1), true); } } // 记录日志 $this->recordSellerLog('添加商品,平台货号:' . $common_id); // 生成F码 if ($common_array['is_fcode'] == 1) { QueueClient::push('createGoodsFCode', array('goods_commonid' => $common_id, 'fc_count' => intval($_POST['g_fccount']), 'fc_prefix' => $_POST['g_fcprefix'])); } redirect(urlShop('store_goods_add', 'add_step_three', array('commonid' => $common_id))); } else { showMessage(L('store_goods_index_goods_add_fail'), getReferer(), 'html', 'error'); } } }
/** * 订单后续其它处理 * */ private function _createOrderStep6() { $ifcart = $this->_post_data['ifcart']; $goods_buy_quantity = $this->_order_data['goods_buy_quantity']; $input_voucher_list = $this->_order_data['input_voucher_list']; $store_cart_list = $this->_order_data['store_cart_list']; $input_buy_items = $this->_order_data['input_buy_items']; $order_list = $this->_order_data['order_list']; $input_address_info = $this->_order_data['input_address_info']; $notice_list = $this->_order_data['notice_list']; $fc_id = $this->_order_data['fc_id']; $ifgroupbuy = $this->_order_data['ifgroupbuy']; //变更库存和销量 QueueClient::push('createOrderUpdateStorage', $goods_buy_quantity); //更新使用的代金券状态 if (!empty($input_voucher_list) && is_array($input_voucher_list)) { QueueClient::push('editVoucherState', $input_voucher_list); } //更新F码使用状态 if ($fc_id) { QueueClient::push('updateGoodsFCode', $fc_id); } //更新抢购购买人数和数量 if ($ifgroupbuy) { foreach ($store_cart_list as $goods_list) { foreach ($goods_list as $goods_info) { if ($goods_info['ifgroupbuy'] && $goods_info['groupbuy_id']) { $groupbuy_info = array(); $groupbuy_info['groupbuy_id'] = $goods_info['groupbuy_id']; $groupbuy_info['quantity'] = $goods_info['goods_num']; QueueClient::push('editGroupbuySaleCount', $groupbuy_info); } } } } //删除购物车中的商品 $this->delCart($ifcart, $this->_member_info['member_id'], array_keys($input_buy_items)); @setNcCookie('cart_goods_num', '', -3600); //保存订单自提点信息 if (C('delivery_isuse') && intval($input_address_info['dlyp_id'])) { $data = array(); $data['mob_phone'] = $input_address_info['mob_phone']; $data['tel_phone'] = $input_address_info['tel_phone']; $data['reciver_name'] = $input_address_info['true_name']; $data['dlyp_id'] = $input_address_info['dlyp_id']; foreach ($order_list as $v) { $data['order_sn_list'][$v['order_id']]['order_sn'] = $v['order_sn']; $data['order_sn_list'][$v['order_id']]['add_time'] = $v['add_time']; } QueueClient::push('saveDeliveryOrder', $data); } //发送提醒类信息 if (!empty($notice_list)) { foreach ($notice_list as $code => $value) { QueueClient::push('sendStoreMsg', array('code' => $code, 'store_id' => key($value), 'param' => current($value))); } } }
/** * 添加会员经验值 * @param unknown $member_info */ public function addExppoint($member_info) { if (empty($member_info)) { return; } //一天内只有第一次登录赠送经验值 if (trim(@date('Y-m-d', $member_info['member_login_time'])) == trim(date('Y-m-d'))) { return; } //加入队列 $queue_content = array(); $queue_content['member_id'] = $member_info['member_id']; $queue_content['member_name'] = $member_info['member_name']; QueueClient::push('addExppoint', $queue_content); }
/** * 预存款支付,依次循环每个订单 * 如果预存款足够就单独支付了该订单,如果不足就暂时冻结,等API支付成功了再彻底扣除 */ public function pdPay($order_list, $input, $buyer_info) { $member_id = $buyer_info['member_id']; $member_name = $buyer_info['member_name']; // $model_payment = Model('payment'); // $pd_payment_info = $model_payment->getPaymentOpenInfo(array('payment_code'=>'predeposit')); // if (empty($pd_payment_info)) return; $available_pd_amount = floatval($buyer_info['available_predeposit']); if ($available_pd_amount <= 0) { return; } $model_order = Model('order'); $model_pd = Model('predeposit'); foreach ($order_list as $order_info) { //货到付款的订单、已经充值卡支付的订单跳过 if ($order_info['payment_code'] == 'offline') { continue; } if ($order_info['order_state'] == ORDER_STATE_PAY) { continue; } $order_amount = floatval($order_info['order_amount']) - floatval($order_info['rcb_amount']); $data_pd = array(); $data_pd['member_id'] = $member_id; $data_pd['member_name'] = $member_name; $data_pd['amount'] = $order_amount; $data_pd['order_sn'] = $order_info['order_sn']; if ($available_pd_amount >= $order_amount) { //预存款立即支付,订单支付完成 $model_pd->changePd('order_pay', $data_pd); $available_pd_amount -= $order_amount; //支付被冻结的充值卡 $rcb_amount = floatval($order_info['rcb_amount']); if ($rcb_amount > 0) { $data_pd = array(); $data_pd['member_id'] = $member_id; $data_pd['member_name'] = $member_name; $data_pd['amount'] = $rcb_amount; $data_pd['order_sn'] = $order_info['order_sn']; $model_pd->changeRcb('order_comb_pay', $data_pd); } //记录订单日志(已付款) $data = array(); $data['order_id'] = $order_info['order_id']; $data['log_role'] = 'buyer'; $data['log_msg'] = L('order_log_pay'); $data['log_orderstate'] = ORDER_STATE_PAY; $insert = $model_order->addOrderLog($data); if (!$insert) { throw new Exception('记录订单预存款支付日志出现错误'); } //订单状态 置为已支付 $data_order = array(); $data_order['order_state'] = ORDER_STATE_PAY; $data_order['payment_time'] = TIMESTAMP; $data_order['payment_code'] = 'predeposit'; $data_order['pd_amount'] = $order_amount; $result = $model_order->editOrder($data_order, array('order_id' => $order_info['order_id'])); if (!$result) { throw new Exception('订单更新失败'); } // 发送商家提醒 $param = array(); $param['code'] = 'new_order'; $param['store_id'] = $order_info['store_id']; $param['param'] = array('order_sn' => $order_info['order_sn']); QueueClient::push('sendStoreMsg', $param); } else { //暂冻结预存款,后面还需要 API彻底完成支付 if ($available_pd_amount > 0) { $data_pd['amount'] = $available_pd_amount; $model_pd->changePd('order_freeze', $data_pd); //预存款支付金额保存到订单 $data_order = array(); $data_order['pd_amount'] = $available_pd_amount; $result = $model_order->editOrder($data_order, array('order_id' => $order_info['order_id'])); $available_pd_amount = 0; if (!$result) { throw new Exception('订单更新失败'); } } } } }
public function complain_verifyOp() { $complain_id = intval($_POST['complain_id']); $complain_info = $this->get_complain_info($complain_id); if (intval($complain_info['complain_state']) === self::STATE_NEW) { $model_complain = Model('complain'); $update_array = array(); $update_array['complain_state'] = self::STATE_APPEAL; $update_array['complain_handle_datetime'] = time(); $update_array['complain_handle_member_id'] = $this->get_admin_id(); $update_array['complain_active'] = self::STATE_ACTIVE; $where_array = array(); $where_array['complain_id'] = $complain_id; if ($model_complain->updateComplain($update_array, $where_array)) { $this->log(L('complain_verify_success') . '[' . $complain_id . ']', 1); // 发送商家消息 $param = array(); $param['code'] = 'complain'; $param['store_id'] = $complain_info['accused_id']; $param['param'] = array('complain_id' => $complain_id); QueueClient::push('sendStoreMsg', $param); showMessage(Language::get('complain_verify_success'), 'index.php?act=complain&op=complain_new_list'); } else { showMessage(Language::get('complain_verify_fail'), 'index.php?act=complain&op=complain_new_list'); } } else { showMessage(Language::get('param_error'), ''); } }
/** * 退款审核页 * */ public function editOp() { $model_refund = Model('refund_return'); $condition = array(); $condition['store_id'] = $_SESSION['store_id']; $condition['refund_id'] = intval($_GET['refund_id']); $refund_list = $model_refund->getRefundList($condition); $refund = $refund_list[0]; if (chksubmit()) { $reload = 'index.php?act=store_refund&lock=1'; if ($refund['order_lock'] == '2') { $reload = 'index.php?act=store_refund&lock=2'; } if ($refund['seller_state'] != '1') {//检查状态,防止页面刷新不及时造成数据错误 showDialog(Language::get('wrong_argument'),$reload,'error'); } $order_id = $refund['order_id']; $refund_array = array(); $refund_array['seller_time'] = time(); $refund_array['seller_state'] = $_POST['seller_state'];//卖家处理状态:1为待审核,2为同意,3为不同意 $refund_array['seller_message'] = $_POST['seller_message']; if ($refund_array['seller_state'] == '3') { $refund_array['refund_state'] = '3';//状态:1为处理中,2为待管理员处理,3为已完成 } else { $refund_array['seller_state'] = '2'; $refund_array['refund_state'] = '2'; } $state = $model_refund->editRefundReturn($condition, $refund_array); if ($state) { if ($refund_array['seller_state'] == '3' && $refund['order_lock'] == '2') { $model_refund->editOrderUnlock($order_id);//订单解锁 } $this->recordSellerLog('退款处理,退款编号:'.$refund['refund_sn']); // 发送买家消息 $param = array(); $param['code'] = 'refund_return_notice'; $param['member_id'] = $refund['buyer_id']; $param['param'] = array( 'refund_url'=> urlShop('member_refund', 'view', array('refund_id' => $refund['refund_id'])), 'refund_sn' => $refund['refund_sn'] ); QueueClient::push('sendMemberMsg', $param); showDialog(Language::get('nc_common_save_succ'),$reload,'succ'); } else { showDialog(Language::get('nc_common_save_fail'),$reload,'error'); } } Tpl::output('refund',$refund); $info['buyer'] = array(); if(!empty($refund['pic_info'])) { $info = unserialize($refund['pic_info']); } Tpl::output('pic_list',$info['buyer']); $model_member = Model('member'); $member = $model_member->getMemberInfoByID($refund['buyer_id']); Tpl::output('member',$member); $condition = array(); $condition['order_id'] = $refund['order_id']; $model_refund->getRightOrderList($condition, $refund['order_goods_id']); Tpl::showpage('store_refund_edit'); }
private function _sendSMsg($code, $store_id, $param) { QueueClient::push('sendStoreMsg', array('code' => $code, 'store_id' => $store_id, 'param' => $param)); }
/** * 编辑商品保存 */ public function edit_save_goodsOp() { $common_id = intval($_POST['commonid']); if (!chksubmit() || $common_id <= 0) { showDialog(L('store_goods_index_goods_edit_fail'), urlShop('store_goods_online', 'index')); } // 验证表单 $obj_validate = new Validate(); $obj_validate->validateparam = array(array("input" => $_POST["g_name"], "require" => "true", "message" => L('store_goods_index_goods_name_null')), array("input" => $_POST["g_price"], "require" => "true", "validator" => "Double", "message" => L('store_goods_index_goods_price_null'))); $error = $obj_validate->validate(); if ($error != '') { showDialog(L('error') . $error, urlShop('store_goods_online', 'index')); } $gc_id = intval($_POST['cate_id']); // 验证商品分类是否存在且商品分类是否为最后一级 $data = Model('goods_class')->getGoodsClassForCacheModel(); if (!isset($data[$gc_id]) || isset($data[$gc_id]['child']) || isset($data[$gc_id]['childchild'])) { showDialog(L('store_goods_index_again_choose_category1')); } // 三方店铺验证是否绑定了该分类 if (!checkPlatformStore()) { //商品分类 by 33hao. com 提供批量显示所有分类插件 $model_bind_class = Model('store_bind_class'); $goods_class = Model('goods_class')->getGoodsClassForCacheModel(); $where['store_id'] = $_SESSION['store_id']; $class_2 = $goods_class[$gc_id]['gc_parent_id']; $class_1 = $goods_class[$class_2]['gc_parent_id']; $where['class_1'] = $class_1; $where['class_2'] = $class_2; $where['class_3'] = $gc_id; $bind_info = $model_bind_class->getStoreBindClassInfo($where); if (empty($bind_info)) { $where['class_3'] = 0; $bind_info = $model_bind_class->getStoreBindClassInfo($where); if (empty($bind_info)) { $where['class_2'] = 0; $where['class_3'] = 0; $bind_info = $model_bind_class->getStoreBindClassInfo($where); if (empty($bind_info)) { $where['class_1'] = 0; $where['class_2'] = 0; $where['class_3'] = 0; $bind_info = $model_bind_class->getStoreBindClassInfo($where); if (empty($bind_info)) { showDialog(L('store_goods_index_again_choose_category2')); } } } } } // 分类信息 $goods_class = Model('goods_class')->getGoodsClassLineForTag(intval($_POST['cate_id'])); $model_goods = Model('goods'); $update_common = array(); $update_common['goods_name'] = $_POST['g_name']; $update_common['goods_jingle'] = $_POST['g_jingle']; $update_common['gc_id'] = $gc_id; $update_common['gc_id_1'] = intval($goods_class['gc_id_1']); $update_common['gc_id_2'] = intval($goods_class['gc_id_2']); $update_common['gc_id_3'] = intval($goods_class['gc_id_3']); $update_common['gc_name'] = $_POST['cate_name']; $update_common['brand_id'] = $_POST['b_id']; $update_common['brand_name'] = $_POST['b_name']; $update_common['type_id'] = intval($_POST['type_id']); $update_common['goods_image'] = $_POST['image_path']; $update_common['goods_price'] = floatval($_POST['g_price']); $update_common['goods_marketprice'] = floatval($_POST['g_marketprice']); $update_common['goods_costprice'] = floatval($_POST['g_costprice']); $update_common['goods_discount'] = floatval($_POST['g_discount']); $update_common['goods_serial'] = $_POST['g_serial']; $update_common['goods_storage_alarm'] = intval($_POST['g_alarm']); $update_common['goods_attr'] = serialize($_POST['attr']); $update_common['goods_body'] = $_POST['g_body']; // 序列化保存手机端商品描述数据 if ($_POST['m_body'] != '') { $_POST['m_body'] = str_replace('"', '"', $_POST['m_body']); $_POST['m_body'] = str_replace('\\', '', $_POST['m_body']); $_POST['m_body'] = json_decode($_POST['m_body'], true); if (!empty($_POST['m_body'])) { $_POST['m_body'] = serialize($_POST['m_body']); } else { $_POST['m_body'] = ''; } } $update_common['mobile_body'] = $_POST['m_body']; $update_common['goods_commend'] = intval($_POST['g_commend']); $update_common['goods_state'] = $this->store_info['store_state'] != 1 ? 0 : intval($_POST['g_state']); // 店铺关闭时,商品下架 $update_common['goods_selltime'] = strtotime($_POST['starttime']) + intval($_POST['starttime_H']) * 3600 + intval($_POST['starttime_i']) * 60; $update_common['goods_verify'] = C('goods_verify') == 1 ? 10 : 1; $update_common['spec_name'] = is_array($_POST['spec']) ? serialize($_POST['sp_name']) : serialize(null); $update_common['spec_value'] = is_array($_POST['spec']) ? serialize($_POST['sp_val']) : serialize(null); $update_common['goods_vat'] = intval($_POST['g_vat']); $update_common['areaid_1'] = intval($_POST['province_id']); $update_common['areaid_2'] = intval($_POST['city_id']); $update_common['transport_id'] = $_POST['freight'] == '0' ? '0' : intval($_POST['transport_id']); // 运费模板 $update_common['transport_title'] = $_POST['transport_title']; $update_common['goods_freight'] = floatval($_POST['g_freight']); //查询店铺商品分类 $goods_stcids_arr = array(); if (!empty($_POST['sgcate_id'])) { $sgcate_id_arr = array(); foreach ($_POST['sgcate_id'] as $k => $v) { $sgcate_id_arr[] = intval($v); } $sgcate_id_arr = array_unique($sgcate_id_arr); $store_goods_class = Model('store_goods_class')->getStoreGoodsClassList(array('store_id' => $_SESSION['store_id'], 'stc_id' => array('in', $sgcate_id_arr), 'stc_state' => '1')); if (!empty($store_goods_class)) { foreach ($store_goods_class as $k => $v) { if ($v['stc_id'] > 0) { $goods_stcids_arr[] = $v['stc_id']; } if ($v['stc_parent_id'] > 0) { $goods_stcids_arr[] = $v['stc_parent_id']; } } $goods_stcids_arr = array_unique($goods_stcids_arr); sort($goods_stcids_arr); } } if (empty($goods_stcids_arr)) { $update_common['goods_stcids'] = ''; } else { $update_common['goods_stcids'] = ',' . implode(',', $goods_stcids_arr) . ','; } $update_common['plateid_top'] = intval($_POST['plate_top']) > 0 ? intval($_POST['plate_top']) : ''; $update_common['plateid_bottom'] = intval($_POST['plate_bottom']) > 0 ? intval($_POST['plate_bottom']) : ''; $update_common['is_virtual'] = intval($_POST['is_gv']); $update_common['virtual_indate'] = $_POST['g_vindate'] != '' ? strtotime($_POST['g_vindate']) + 24 * 60 * 60 - 1 : 0; // 当天的最后一秒结束 $update_common['virtual_limit'] = intval($_POST['g_vlimit']) > 10 || intval($_POST['g_vlimit']) < 0 ? 10 : intval($_POST['g_vlimit']); $update_common['virtual_invalid_refund'] = intval($_POST['g_vinvalidrefund']); $update_common['is_fcode'] = intval($_POST['is_fc']); $update_common['is_appoint'] = intval($_POST['is_appoint']); // 只有库存为零的商品可以预约 $update_common['appoint_satedate'] = $update_common['is_appoint'] == 1 ? strtotime($_POST['g_saledate']) : ''; // 预约商品的销售时间 $update_common['is_presell'] = $update_common['goods_state'] == 1 ? intval($_POST['is_presell']) : 0; // 只有出售中的商品可以预售 $update_common['presell_deliverdate'] = $update_common['is_presell'] == 1 ? strtotime($_POST['g_deliverdate']) : ''; // 预售商品的发货时间 $update_common['is_own_shop'] = in_array($_SESSION['store_id'], model('store')->getOwnShopIds()) ? 1 : 0; // 开始事务 Model()->beginTransaction(); $model_gift = Model('goods_gift'); // 清除原有规格数据 $model_type = Model('type'); $model_type->delGoodsAttr(array('goods_commonid' => $common_id)); // 生成商品二维码 require_once BASE_RESOURCE_PATH . DS . 'phpqrcode' . DS . 'index.php'; $PhpQRCode = new PhpQRCode(); $PhpQRCode->set('pngTempDir', BASE_UPLOAD_PATH . DS . ATTACH_STORE . DS . $_SESSION['store_id'] . DS); // 更新商品规格 $goodsid_array = array(); $colorid_array = array(); if (is_array($_POST['spec'])) { foreach ($_POST['spec'] as $value) { $goods_info = $model_goods->getGoodsInfo(array('goods_id' => $value['goods_id'], 'goods_commonid' => $common_id, 'store_id' => $_SESSION['store_id']), 'goods_id'); if (!empty($goods_info)) { $goods_id = $goods_info['goods_id']; $update = array(); $update['goods_commonid'] = $common_id; $update['goods_name'] = $update_common['goods_name'] . ' ' . implode(' ', $value['sp_value']); $update['goods_jingle'] = $update_common['goods_jingle']; $update['store_id'] = $_SESSION['store_id']; $update['store_name'] = $_SESSION['store_name']; $update['gc_id'] = $update_common['gc_id']; $update['gc_id_1'] = $update_common['gc_id_1']; $update['gc_id_2'] = $update_common['gc_id_2']; $update['gc_id_3'] = $update_common['gc_id_3']; $update['brand_id'] = $update_common['brand_id']; $update['goods_price'] = $value['price']; $update['goods_marketprice'] = $value['marketprice'] == 0 ? $update_common['goods_marketprice'] : $value['marketprice']; $update['goods_serial'] = $value['sku']; $update['goods_storage_alarm'] = intval($value['alarm']); $update['goods_spec'] = serialize($value['sp_value']); $update['goods_storage'] = $value['stock']; $update['goods_state'] = $update_common['goods_state']; $update['goods_verify'] = $update_common['goods_verify']; $update['goods_edittime'] = TIMESTAMP; $update['areaid_1'] = $update_common['areaid_1']; $update['areaid_2'] = $update_common['areaid_2']; $update['color_id'] = intval($value['color']); $update['transport_id'] = $update_common['transport_id']; $update['goods_freight'] = $update_common['goods_freight']; $update['goods_vat'] = $update_common['goods_vat']; $update['goods_commend'] = $update_common['goods_commend']; $update['goods_stcids'] = $update_common['goods_stcids']; $update['is_virtual'] = $update_common['is_virtual']; $update['virtual_indate'] = $update_common['virtual_indate']; $update['virtual_limit'] = $update_common['virtual_limit']; $update['virtual_invalid_refund'] = $update_common['virtual_invalid_refund']; $update['is_fcode'] = $update_common['is_fcode']; $update['is_appoint'] = $update_common['is_appoint']; $update['is_presell'] = $update_common['is_presell']; // 虚拟商品不能有赠品 if ($update_common['is_virtual'] == 1) { $update['have_gift'] = 0; $model_gift->delGoodsGift(array('goods_id' => $goods_id)); } $update['is_own_shop'] = $update_common['is_own_shop']; $model_goods->editGoodsById($update, $goods_id); // 生成商品二维码 $PhpQRCode->set('date', WAP_SITE_URL . '/tmpl/product_detail.html?goods_id=' . $goods_id); $PhpQRCode->set('pngTempName', $goods_id . '.png'); $PhpQRCode->init(); } else { $insert = array(); $insert['goods_commonid'] = $common_id; $insert['goods_name'] = $update_common['goods_name'] . ' ' . implode(' ', $value['sp_value']); $insert['goods_jingle'] = $update_common['goods_jingle']; $insert['store_id'] = $_SESSION['store_id']; $insert['store_name'] = $_SESSION['store_name']; $insert['gc_id'] = $update_common['gc_id']; $insert['gc_id_1'] = $update_common['gc_id_1']; $insert['gc_id_2'] = $update_common['gc_id_2']; $insert['gc_id_3'] = $update_common['gc_id_3']; $insert['brand_id'] = $update_common['brand_id']; $insert['goods_price'] = $value['price']; $insert['goods_promotion_price'] = $value['price']; $insert['goods_marketprice'] = $value['marketprice'] == 0 ? $update_common['goods_marketprice'] : $value['marketprice']; $insert['goods_serial'] = $value['sku']; $insert['goods_storage_alarm'] = intval($value['alarm']); $insert['goods_spec'] = serialize($value['sp_value']); $insert['goods_storage'] = $value['stock']; $insert['goods_image'] = $update_common['goods_image']; $insert['goods_state'] = $update_common['goods_state']; $insert['goods_verify'] = $update_common['goods_verify']; $insert['goods_addtime'] = TIMESTAMP; $insert['goods_edittime'] = TIMESTAMP; $insert['areaid_1'] = $update_common['areaid_1']; $insert['areaid_2'] = $update_common['areaid_2']; $insert['color_id'] = intval($value['color']); $insert['transport_id'] = $update_common['transport_id']; $insert['goods_freight'] = $update_common['goods_freight']; $insert['goods_vat'] = $update_common['goods_vat']; $insert['goods_commend'] = $update_common['goods_commend']; $insert['goods_stcids'] = $update_common['goods_stcids']; $insert['is_virtual'] = $update_common['is_virtual']; $insert['virtual_indate'] = $update_common['virtual_indate']; $insert['virtual_limit'] = $update_common['virtual_limit']; $insert['virtual_invalid_refund'] = $update_common['virtual_invalid_refund']; $insert['is_fcode'] = $update_common['is_fcode']; $insert['is_appoint'] = $update_common['is_appoint']; $insert['is_presell'] = $update_common['is_presell']; $insert['is_own_shop'] = $update_common['is_own_shop']; $goods_id = $model_goods->addGoods($insert); // 生成商品二维码 $PhpQRCode->set('date', WAP_SITE_URL . '/tmpl/product_detail.html?goods_id=' . $goods_id); $PhpQRCode->set('pngTempName', $goods_id . '.png'); $PhpQRCode->init(); } $goodsid_array[] = intval($goods_id); $colorid_array[] = intval($value['color']); $model_type->addGoodsType($goods_id, $common_id, array('cate_id' => $_POST['cate_id'], 'type_id' => $_POST['type_id'], 'attr' => $_POST['attr'])); } } else { $goods_info = $model_goods->getGoodsInfo(array('goods_spec' => serialize(null), 'goods_commonid' => $common_id, 'store_id' => $_SESSION['store_id']), 'goods_id'); if (!empty($goods_info)) { $goods_id = $goods_info['goods_id']; $update = array(); $update['goods_commonid'] = $common_id; $update['goods_name'] = $update_common['goods_name']; $update['goods_jingle'] = $update_common['goods_jingle']; $update['store_id'] = $_SESSION['store_id']; $update['store_name'] = $_SESSION['store_name']; $update['gc_id'] = $update_common['gc_id']; $update['gc_id_1'] = $update_common['gc_id_1']; $update['gc_id_2'] = $update_common['gc_id_2']; $update['gc_id_3'] = $update_common['gc_id_3']; $update['brand_id'] = $update_common['brand_id']; $update['goods_price'] = $update_common['goods_price']; $update['goods_marketprice'] = $update_common['goods_marketprice']; $update['goods_serial'] = $update_common['goods_serial']; $update['goods_storage_alarm'] = $update_common['goods_storage_alarm']; $update['goods_spec'] = serialize(null); $update['goods_storage'] = intval($_POST['g_storage']); $update['goods_state'] = $update_common['goods_state']; $update['goods_verify'] = $update_common['goods_verify']; $update['goods_edittime'] = TIMESTAMP; $update['areaid_1'] = $update_common['areaid_1']; $update['areaid_2'] = $update_common['areaid_2']; $update['color_id'] = 0; $update['transport_id'] = $update_common['transport_id']; $update['goods_freight'] = $update_common['goods_freight']; $update['goods_vat'] = $update_common['goods_vat']; $update['goods_commend'] = $update_common['goods_commend']; $update['goods_stcids'] = $update_common['goods_stcids']; $update['is_virtual'] = $update_common['is_virtual']; $update['virtual_indate'] = $update_common['virtual_indate']; $update['virtual_limit'] = $update_common['virtual_limit']; $update['virtual_invalid_refund'] = $update_common['virtual_invalid_refund']; $update['is_fcode'] = $update_common['is_fcode']; $update['is_appoint'] = $update_common['is_appoint']; $update['is_presell'] = $update_common['is_presell']; if ($update_common['is_virtual'] == 1) { $update['have_gift'] = 0; $model_gift->delGoodsGift(array('goods_id' => $goods_id)); } $update['is_own_shop'] = $update_common['is_own_shop']; $model_goods->editGoodsById($update, $goods_id); // 生成商品二维码 $PhpQRCode->set('date', WAP_SITE_URL . '/tmpl/product_detail.html?goods_id=' . $goods_id); $PhpQRCode->set('pngTempName', $goods_id . '.png'); $PhpQRCode->init(); } else { $insert = array(); $insert['goods_commonid'] = $common_id; $insert['goods_name'] = $update_common['goods_name']; $insert['goods_jingle'] = $update_common['goods_jingle']; $insert['store_id'] = $_SESSION['store_id']; $insert['store_name'] = $_SESSION['store_name']; $insert['gc_id'] = $update_common['gc_id']; $insert['gc_id_1'] = $update_common['gc_id_1']; $insert['gc_id_2'] = $update_common['gc_id_2']; $insert['gc_id_3'] = $update_common['gc_id_3']; $insert['brand_id'] = $update_common['brand_id']; $insert['goods_price'] = $update_common['goods_price']; $insert['goods_promotion_price'] = $update_common['goods_price']; $insert['goods_marketprice'] = $update_common['goods_marketprice']; $insert['goods_serial'] = $update_common['goods_serial']; $insert['goods_storage_alarm'] = $update_common['goods_storage_alarm']; $insert['goods_spec'] = serialize(null); $insert['goods_storage'] = intval($_POST['g_storage']); $insert['goods_image'] = $update_common['goods_image']; $insert['goods_state'] = $update_common['goods_state']; $insert['goods_verify'] = $update_common['goods_verify']; $insert['goods_addtime'] = TIMESTAMP; $insert['goods_edittime'] = TIMESTAMP; $insert['areaid_1'] = $update_common['areaid_1']; $insert['areaid_2'] = $update_common['areaid_2']; $insert['color_id'] = 0; $insert['transport_id'] = $update_common['transport_id']; $insert['goods_freight'] = $update_common['goods_freight']; $insert['goods_vat'] = $update_common['goods_vat']; $insert['goods_commend'] = $update_common['goods_commend']; $insert['goods_stcids'] = $update_common['goods_stcids']; $insert['is_virtual'] = $update_common['is_virtual']; $insert['virtual_indate'] = $update_common['virtual_indate']; $insert['virtual_limit'] = $update_common['virtual_limit']; $insert['virtual_invalid_refund'] = $update_common['virtual_invalid_refund']; $insert['is_fcode'] = $update_common['is_fcode']; $insert['is_appoint'] = $update_common['is_appoint']; $insert['is_presell'] = $update_common['is_presell']; $insert['is_own_shop'] = $update_common['is_own_shop']; $goods_id = $model_goods->addGoods($insert); } $goodsid_array[] = intval($goods_id); $colorid_array[] = 0; $model_type->addGoodsType($goods_id, $common_id, array('cate_id' => $_POST['cate_id'], 'type_id' => $_POST['type_id'], 'attr' => $_POST['attr'])); } // 生成商品二维码 if (!empty($goodsid_array)) { //QueueClient::push('createGoodsQRCode', array('store_id' => $_SESSION['store_id'], 'goodsid_array' => $goodsid_array)); // 生成商品二维码 $PhpQRCode->set('date', WAP_SITE_URL . '/tmpl/product_detail.html?goods_id=' . $goods_id); $PhpQRCode->set('pngTempName', $goods_id . '.png'); $PhpQRCode->init(); } // 清理商品数据 $model_goods->delGoods(array('goods_id' => array('not in', $goodsid_array), 'goods_commonid' => $common_id, 'store_id' => $_SESSION['store_id'])); // 清理商品图片表 $colorid_array = array_unique($colorid_array); $model_goods->delGoodsImages(array('goods_commonid' => $common_id, 'color_id' => array('not in', $colorid_array))); // 更新商品默认主图 $default_image_list = $model_goods->getGoodsImageList(array('goods_commonid' => $common_id, 'is_default' => 1), 'color_id,goods_image'); if (!empty($default_image_list)) { foreach ($default_image_list as $val) { $model_goods->editGoods(array('goods_image' => $val['goods_image']), array('goods_commonid' => $common_id, 'color_id' => $val['color_id'])); } } // 商品加入上架队列 if (isset($_POST['starttime'])) { $selltime = strtotime($_POST['starttime']) + intval($_POST['starttime_H']) * 3600 + intval($_POST['starttime_i']) * 60; if ($selltime > TIMESTAMP) { $this->addcron(array('exetime' => $selltime, 'exeid' => $common_id, 'type' => 1), true); } } // 添加操作日志 $this->recordSellerLog('编辑商品,平台货号:' . $common_id); if ($update_common['is_virtual'] == 1 || $update_common['is_fcode'] == 1 || $update_common['is_presell'] == 1) { // 如果是特殊商品清理促销活动,抢购、限时折扣、组合销售 QueueClient::push('clearSpecialGoodsPromotion', array('goods_commonid' => $common_id, 'goodsid_array' => $goodsid_array)); } else { // 更新商品促销价格 QueueClient::push('updateGoodsPromotionPriceByGoodsCommonId', $common_id); } // 生成F码 if ($update_common['is_fcode'] == 1) { QueueClient::push('createGoodsFCode', array('goods_commonid' => $common_id, 'fc_count' => intval($_POST['g_fccount']), 'fc_prefix' => $_POST['g_fcprefix'])); } $return = $model_goods->editGoodsCommon($update_common, array('goods_commonid' => $common_id, 'store_id' => $_SESSION['store_id'])); if ($return) { //提交事务 Model()->commit(); showDialog(L('nc_common_op_succ'), $_POST['ref_url'], 'succ'); } else { //回滚事务 Model()->rollback(); showDialog(L('store_goods_index_goods_edit_fail'), urlShop('store_goods_online', 'index')); } }
/** * 限时折扣商品删除 **/ public function xianshi_goods_deleteOp() { $model_xianshi_goods = Model('p_xianshi_goods'); $model_xianshi = Model('p_xianshi'); $data = array(); $data['result'] = true; $xianshi_goods_id = intval($_POST['xianshi_goods_id']); $xianshi_goods_info = $model_xianshi_goods->getXianshiGoodsInfoByID($xianshi_goods_id); if (!$xianshi_goods_info) { $data['result'] = false; $data['message'] = L('param_error'); echo json_encode($data); die; } $xianshi_info = $model_xianshi->getXianshiInfoByID($xianshi_goods_info['xianshi_id'], $_SESSION['store_id']); if (!$xianshi_info) { $data['result'] = false; $data['message'] = L('param_error'); echo json_encode($data); die; } if (!$model_xianshi_goods->delXianshiGoods(array('xianshi_goods_id' => $xianshi_goods_id))) { $data['result'] = false; $data['message'] = L('xianshi_goods_delete_fail'); echo json_encode($data); die; } // 添加对列修改商品促销价格 QueueClient::push('updateGoodsPromotionPriceByGoodsId', $xianshi_goods_info['goods_id']); $this->recordSellerLog('删除限时折扣商品,活动名称:' . $xianshi_info['xianshi_name'] . ',商品名称:' . $xianshi_goods_info['goods_name']); echo json_encode($data); die; }