public function getRequestUrl($orderId, $returnUrl, $notifyUrl) { // 参数验证 $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl)); $orderId = $validator->required()->digits()->min(1)->validate('orderId'); $returnUrl = $validator->required()->validate('returnUrl'); $notifyUrl = $validator->required()->validate('notifyUrl'); $this->validate($validator); //设置订单 ID $this->orderId = $orderId; // 取得订单 $orderBasicService = new OrderBasicService(); $orderInfo = $orderBasicService->loadOrderInfoById($orderId); if (empty($orderInfo) || $orderInfo->isEmpty()) { throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']'); } $desc = $orderInfo['order_id'] . '|' . Money::toSmartyDisplay($orderInfo['order_amount']) . '|' . $orderInfo['system_id'] . '|WAP'; // 构造要请求的参数数组,无需改动 $parameterCreate = array("req_data" => '<direct_trade_create_req><subject>' . $desc . '</subject><out_trade_no>' . $orderInfo['order_sn'] . '_' . $orderInfo['order_id'] . '</out_trade_no><total_fee>' . Money::toDisplay($orderInfo['order_amount'], 2) . "</total_fee><seller_account_name>" . $this->account . "</seller_account_name><notify_url>" . $notifyUrl . "</notify_url><out_user>" . $orderInfo['user_id'] . "</out_user><merchant_url></merchant_url>" . "<call_back_url>" . $returnUrl . "</call_back_url></direct_trade_create_req>", "service" => $this->configServiceCreate, "sec_id" => $this->configSecId, "partner" => $this->partnerId, "req_id" => date("Ymdhms"), "format" => $this->configFormat, "v" => $this->configVersion); // 首先申请 Token $result = $this->callAlipayWapGateway($this->buildRequestLinkData($parameterCreate)); // 调用GetToken方法,并返回token $token = $this->getToken($result); if (!$token) { printLog($this->getGatewayType() . ' 获取 token 失败'); return null; } // 构造要请求的参数数组,无需改动 $parameterExecute = array("req_data" => "<auth_and_execute_req><request_token>" . $token . "</request_token></auth_and_execute_req>", "service" => $this->configServiceExecute, "sec_id" => $this->configSecId, "partner" => $this->partnerId, "call_back_url" => $returnUrl, "format" => $this->configFormat, "v" => $this->configVersion); return $this->configGateway . $this->buildRequestLinkData($parameterExecute); }
/** * 取得一个订单的输出 Txt * * */ private function getOrderTxt($orderReferInfo, $orderGoodsArray) { $retTxt = ''; $orderGoodsNameStr = ''; $coupon = $orderReferInfo['surplus'] + $orderReferInfo['bonus']; // 商品总价 $orderAmount = $orderReferInfo['goods_amount'] - $orderReferInfo['discount'] - $orderReferInfo['extra_discount'] - $orderReferInfo['refund']; // 商品总的额外退款金额 $orderExtraRefund = 0; // 订单状态 $orderStatus = 'refund'; switch ($orderReferInfo['pay_status']) { case OrderBasicService::PS_UNPAYED: $orderStatus = 'unpay'; break; case OrderBasicService::PS_PAYED: $orderStatus = 'pay'; break; default: $orderStatus = 'refund'; } // 对订单中每个商品单独计算 foreach ($orderGoodsArray as $orderGoodsItem) { $orderGoodsNameStr .= '{(' . $orderGoodsItem['goods_id'] . ')' . $orderGoodsItem['goods_name'] . '[' . $orderGoodsItem['goods_number'] . ' 件]},'; if (OrderGoodsService::OGS_UNPAY != $orderGoodsItem['order_goods_status'] && OrderGoodsService::OGS_PAY != $orderGoodsItem['order_goods_status']) { // 有一个 order_goods 是退款状态,整个订单就是退款状态 $orderStatus = 'refund'; } // 累计额外退款的总金额 $orderExtraRefund += $orderGoodsItem['extra_refund']; } $orderGoodsNameStr = str_replace('|', '_', $orderGoodsNameStr); $orderGoodsNameStr = mb_substr($orderGoodsNameStr, 0, 240); $referParamArray = json_decode($orderReferInfo['refer_param'], true); // CPS 应付总价 $orderAmountOfCps = $orderAmount - $coupon - $orderExtraRefund; $orderAmountOfCps = $orderAmountOfCps > 0 ? $orderAmountOfCps : 0; // QQ订单要多输出一条记录 if ('qqlogin' == $orderReferInfo['login_type']) { // 取得QQ登陆用户的信息 static $userBasicService = null; if (null == $userBasicService) { $userBasicService = new UserBasicService(); } $userInfo = $userBasicService->loadUserById($orderReferInfo['user_id']); //取得 QQ 用户的 openId ,QQ登陆的用户 sns_login 例子 qq:476BA0B2332440759D485548637DFCDD $qqUserOpenId = $userInfo->sns_login; $qqUserOpenId = substr($qqUserOpenId, strpos($qqUserOpenId, ':') + 1); //输出 QQ 登陆的记录 $retTxt .= $referParamArray['wi'] . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['add_time'])) . "||" . $orderReferInfo['order_id'] . "||" . Money::toSmartyDisplay($orderAmountOfCps) . "||" . $orderGoodsNameStr . "||" . $orderStatus . "||" . $orderStatus . "||alipay" . "||" . Money::toSmartyDisplay($orderReferInfo['shipping_fee']) . "||" . Money::toSmartyDisplay($coupon) . "||0" . "||" . $qqUserOpenId . "||" . 'bangzhufu' . "||" . 'qqlogin003' . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['update_time'])) . "\n"; } if ('YIQIFACPS' != $orderReferInfo['utm_source']) { // 不是亿起发的订单 goto out; } //输出 亿起发 的订单记录 $retTxt .= $referParamArray['wi'] . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['add_time'])) . "||" . $orderReferInfo['order_id'] . "||" . Money::toSmartyDisplay($orderAmountOfCps) . "||" . $orderGoodsNameStr . "||" . $orderStatus . "||" . $orderStatus . "||alipay" . "||" . Money::toSmartyDisplay($orderReferInfo['shipping_fee']) . "||" . Money::toSmartyDisplay($coupon) . "||0" . "||" . "||" . "||" . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['update_time'])) . "\n"; out: return $retTxt; }
private function outputDataRow($activeSheet, $rowIndex, $orderGoodsItem, $excludeKeyArray = null) { // 代表价格的列,需要特殊处理显示格式 $priceColumnArray = array('suppliers_price', 'suppliers_total_price', 'suppliers_shipping_fee', 'refund', 'extra_refund', 'goods_price', 'shipping_fee', 'discount', 'extra_discount'); // 输出数据 $colIndex = 4; foreach ($this->filterArray as $key => $value) { if (!empty($excludeKeyArray) && in_array($key, $excludeKeyArray)) { $colIndex++; continue; } $cellValue = isset($orderGoodsItem[$key]) ? $orderGoodsItem[$key] : ''; if (in_array($key, $priceColumnArray)) { // 金额需要做转化 $cellValue = Money::toSmartyDisplay($cellValue); $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue); } else { $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue); $activeSheet->getCellByColumnAndRow($colIndex, $rowIndex)->setDataType(\PHPExcel_Cell_DataType::TYPE_STRING); } // 客服备注用黄色标明 if ('memo' == $key) { $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFFFFF00'); } // 不是付款订单,用红色标注 (退款订单) if (1 != $orderGoodsItem['order_goods_status']) { $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFFF0000'); } $colIndex++; } }
public function getOrderReferNotifyUrl($f3, $orderRefer) { if (!('YIQIFACPS' == $orderRefer->utm_source || 'qqlogin' == $orderRefer->login_type && empty($orderRefer->utm_source))) { // 不是亿起发的订单,或者不是QQ登陆订单 return null; } $notifyUrlArray = array(); // 取得记录的 亿起发 参数 $referParamArray = json_decode($orderRefer->refer_param, true); // 取得订单信息 $orderBasicService = new OrderBasicService(); $orderInfo = $orderBasicService->loadOrderInfoById($orderRefer->order_id); // 取得订单商品详情 $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderRefer->order_id); // 计算佣金 $orderGoodsNameStr = ''; $coupon = $orderInfo->surplus + $orderInfo->bonus; // 商品总价 $orderAmount = $orderInfo->goods_amount - $orderInfo->discount - $orderInfo->extra_discount - $orderInfo->refund; // 商品总的额外退款金额 $orderExtraRefund = 0; // 对订单中每个商品单独计算 foreach ($orderGoodsArray as $orderGoodsItem) { $orderGoodsNameStr .= '{(' . $orderGoodsItem['goods_id'] . ')' . $orderGoodsItem['goods_name'] . '[' . $orderGoodsItem['goods_number'] . ' 件]},'; // 累计额外退款的总金额 $orderExtraRefund += $orderGoodsItem['extra_refund']; } // CPS 应付总价 $orderAmountOfCps = $orderAmount - $coupon - $orderExtraRefund; $orderAmountOfCps = $orderAmountOfCps > 0 ? $orderAmountOfCps : 0; $orderGoodsNameStr = str_replace('|', '_', $orderGoodsNameStr); $orderGoodsNameStr = mb_substr($orderGoodsNameStr, 0, 240); // 推送QQ登陆订单 if ('qqlogin' == $orderRefer->login_type) { // 取得QQ登陆用户的信息 $userBasicService = new UserBasicService(); $userInfo = $userBasicService->loadUserById($orderInfo->user_id); //取得 QQ 用户的 openId ,QQ登陆的用户 sns_login 例子 qq:476BA0B2332440759D485548637DFCDD $qqUserOpenId = $userInfo->sns_login; $qqUserOpenId = substr($qqUserOpenId, strpos($qqUserOpenId, ':') + 1); // QQ 登陆需要额外推单 $param = "cid=6406" . "&wid=435983" . "&qqoid=" . $qqUserOpenId . "&qqmid=bangzhufu" . "&ct=qqlogin003" . "&on=" . $orderInfo->order_id . "&ta=1" . "&dt=" . YiqifaCpsRefer::$notifyParamDt . "&pp=" . Money::toSmartyDisplay($orderAmountOfCps) . "&sd=" . urlencode(date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderInfo->add_time))) . "&os=pay" . "&ps=pay" . "&pw=alipay" . "&far=" . Money::toSmartyDisplay($orderInfo->shipping_fee) . "&fav=" . Money::toSmartyDisplay($coupon) . "&fac=0" . "&encoding=utf-8"; // QQ 登陆订单推送 $notifyUrlArray[] = YiqifaCpsRefer::yiqifaNotifyGateway . $param; } if ('YIQIFACPS' != $orderRefer->utm_source) { // 不是亿起发的订单 goto out; } // 亿起发 正常 CPS 推单 $param = "cid=" . $referParamArray['cid'] . "&wi=" . $referParamArray['wi'] . "&on=" . $orderInfo->order_id . "&ta=1" . "&pna=" . urlencode($orderGoodsNameStr) . "&dt=" . YiqifaCpsRefer::$notifyParamDt . "&pp=" . Money::toSmartyDisplay($orderAmountOfCps) . "&sd=" . urlencode(date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderInfo->add_time))) . "&os=pay" . "&ps=pay" . "&pw=alipay" . "&far=" . Money::toSmartyDisplay($orderInfo->shipping_fee) . "&fav=" . Money::toSmartyDisplay($coupon) . "&fac=0" . "&encoding=utf-8"; // 亿起发订单推送 $notifyUrlArray[] = YiqifaCpsRefer::yiqifaNotifyGateway . $param; out: return $notifyUrlArray; }
private function getGoodsItemXml($index, $goodsItem, $goodsIdToGalleryArray) { global $f3; $siteName = $f3->get('sysConfig[site_name]'); $goodsViewUrl = RouteHelper::makeUrl('/Goods/View', array('goods_id' => $goodsItem['goods_id']), false, true); $goodsViewUrl = RouteHelper::addParam($goodsViewUrl, array('utm_source' => 'baidutuan')); $goodsImageUrl = ''; if (isset($goodsIdToGalleryArray[$goodsItem['goods_id']])) { $goodsImageUrl = RouteHelper::makeImageUrl($goodsIdToGalleryArray[$goodsItem['goods_id']][0]['img_url']); } // 购买数量 $bought = $goodsItem['virtual_buy_number'] + $goodsItem['user_pay_number']; // 转换价格显示 $goodsItem['market_price'] = Money::toSmartyDisplay($goodsItem['market_price']); $goodsItem['shop_price'] = Money::toSmartyDisplay($goodsItem['shop_price']); $rebate = 0; if ($goodsItem['market_price'] > 0) { $rebate = 10 * round($goodsItem['shop_price'] / $goodsItem['market_price'], 2); } $today = strtotime(date('Ymd')); $twoDaysLater = $today + 86400 * 2; $xmlitem = <<<XMLITEM \t<url> \t <loc><![CDATA[{$goodsViewUrl}]]></loc> \t <data><display> \t\t<website><![CDATA[{$siteName}]]></website> \t\t<siteurl><![CDATA[{$this->siteUrl}]]></siteurl> \t\t<city>全国</city> \t\t<title><![CDATA[{$goodsItem['goods_name']}]]></title> \t\t<image><![CDATA[{$goodsImageUrl}]]></image> \t\t<startTime>{$today}</startTime> \t\t<endTime>{$twoDaysLater}</endTime> <value>{$goodsItem['market_price']}</value> <price>{$goodsItem['shop_price']}</price> <rebate>{$rebate}</rebate> <bought>{$bought}</bought> </display></data> </url> XMLITEM; return $xmlitem; }
public function getRequestUrl($orderId, $returnUrl, $notifyUrl) { // 参数验证 $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl)); $orderId = $validator->required()->digits()->min(1)->validate('orderId'); $returnUrl = $validator->required()->validate('returnUrl'); $notifyUrl = $validator->required()->validate('notifyUrl'); $this->validate($validator); //设置订单 ID $this->orderId = $orderId; // 取得订单 $orderBasicService = new OrderBasicService(); $orderInfo = $orderBasicService->loadOrderInfoById($orderId); if (empty($orderInfo) || $orderInfo->isEmpty()) { throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']'); } $desc = $orderInfo['order_id'] . '|' . Money::toSmartyDisplay($orderInfo['order_amount']) . '|' . $orderInfo['system_id']; //构造要请求的参数数组,无需改动 $parameter = array("service" => "create_direct_pay_by_user", "partner" => $this->partnerId, "payment_type" => 1, "notify_url" => $notifyUrl, "return_url" => $returnUrl, "seller_email" => $this->account, "out_trade_no" => $orderInfo['order_sn'] . '_' . $orderInfo['order_id'], "subject" => $desc, "total_fee" => Money::toDisplay($orderInfo['order_amount'], 2), "body" => $desc, "show_url" => '', "anti_phishing_key" => '', "exter_invoke_ip" => '', "_input_charset" => 'utf-8'); //建立请求 $alipaySubmit = new AlipaySubmit($this->alipayConfig); return $alipaySubmit->buildRequestUrl($parameter); }
public function getRequestUrl($orderId, $returnUrl, $notifyUrl) { // 参数验证 $validator = new Validator(array('orderId' => $orderId, 'returnUrl' => $returnUrl, 'notifyUrl' => $notifyUrl)); $orderId = $validator->required()->digits()->min(1)->validate('orderId'); $returnUrl = $validator->required()->validate('returnUrl'); $notifyUrl = $validator->required()->validate('notifyUrl'); $this->validate($validator); //设置订单 ID $this->orderId = $orderId; // 取得订单 $orderBasicService = new OrderBasicService(); $orderInfo = $orderBasicService->loadOrderInfoById($orderId); if (empty($orderInfo) || $orderInfo->isEmpty()) { throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']'); } $desc = $orderInfo['order_id'] . '|' . Money::toSmartyDisplay($orderInfo['order_amount']) . '|' . $orderInfo['system_id']; // 创建支付请求对象 $reqHandler = new RequestHandler(); $reqHandler->init(); $reqHandler->setKey($this->partnerKey); $reqHandler->setGateUrl("https://gw.tenpay.com/gateway/pay.htm"); //设置支付参数 $reqHandler->setParameter("partner", $this->partnerId); $reqHandler->setParameter("out_trade_no", $orderInfo['order_sn'] . '_' . $orderId); $reqHandler->setParameter("total_fee", Money::storageToCent($orderInfo['order_amount'])); //总金额 $reqHandler->setParameter("return_url", $returnUrl); $reqHandler->setParameter("notify_url", $notifyUrl); $reqHandler->setParameter("body", $desc); $reqHandler->setParameter("bank_type", $this->bankType); //银行类型,默认为财付通, DEFAULT //用户ip $reqHandler->setParameter("spbill_create_ip", $_SERVER['REMOTE_ADDR']); //客户端IP $reqHandler->setParameter("fee_type", "1"); //币种 $reqHandler->setParameter("subject", mb_substr($desc, 0, 32)); //商品名称,(中介交易时必填) //系统可选参数 $reqHandler->setParameter("sign_type", "MD5"); //签名方式,默认为MD5,可选RSA $reqHandler->setParameter("service_version", "1.0"); //接口版本号 $reqHandler->setParameter("input_charset", "utf-8"); //字符集 $reqHandler->setParameter("sign_key_index", "1"); //密钥序号 //业务可选参数 $reqHandler->setParameter("attach", ""); //附件数据,原样返回就可以了 $reqHandler->setParameter("product_fee", ""); //商品费用 $reqHandler->setParameter("transport_fee", "0"); //物流费用 $reqHandler->setParameter("time_start", date("YmdHis", Time::gmTimeToChinaTime($orderInfo['add_time']))); //订单生成时间 $reqHandler->setParameter("time_expire", ""); //订单失效时间 $reqHandler->setParameter("buyer_id", ""); //买方财付通帐号 $reqHandler->setParameter("goods_tag", ""); //商品标记 $reqHandler->setParameter("trade_mode", $this->tradeMode); //交易模式(1.即时到帐模式,2.中介担保模式,3.后台选择(卖家进入支付中心列表选择)) $reqHandler->setParameter("transport_desc", ""); //物流说明 $reqHandler->setParameter("trans_type", "1"); //交易类型 $reqHandler->setParameter("agentid", ""); //平台ID $reqHandler->setParameter("agent_type", ""); //代理模式(0.无代理,1.表示卡易售模式,2.表示网店模式) $reqHandler->setParameter("seller_id", ""); //卖家的商户号 //请求的URL $reqUrl = $reqHandler->getRequestURL(); //获取debug信息,建议把请求和debug信息写入日志,方便定位问题 $debugInfo = $reqHandler->getDebugInfo(); return $reqUrl; }
/** * 设置订单的信息,注意:这个方法里面糅合了很多功能,通过 action="xxxx" 来区分 * * @param $f3 */ public function Update($f3) { // 验证 action $validator = new Validator($f3->get('GET')); $action = $validator->required()->oneOf(array('set_extra_discount', 'set_suppliers_price', 'set_shipping_no', 'set_memo', 'set_refund', 'set_extra_refund'), '非法操作')->validate('action'); if (!$this->validate($validator)) { goto out; } // 验证提交上来的参数 $validator = new Validator($f3->get('POST')); $updateValueArray = array(); $rec_id = $validator->required()->digits()->min(1)->validate('rec_id'); // 针对不同的 action 做不同的验证 switch ($action) { case 'set_extra_discount': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_extra_discount'); $updateValueArray['extra_discount'] = Money::toStorage($validator->validate('extra_discount')); $updateValueArray['extra_discount_note'] = $validator->required()->validate('extra_discount_note'); break; case 'set_suppliers_price': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_suppliers_price'); $updateValueArray['suppliers_price'] = Money::toStorage($validator->validate('suppliers_price')); $updateValueArray['suppliers_shipping_fee'] = Money::toStorage($validator->validate('suppliers_shipping_fee')); break; case 'set_shipping_no': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_shipping_no'); $updateValueArray['shipping_id'] = $validator->digits()->min(1)->validate('shipping_id'); $updateValueArray['shipping_no'] = $validator->validate('shipping_no'); break; case 'set_memo': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_memo'); $updateValueArray['memo'] = $validator->validate('memo'); break; case 'set_refund': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_refund'); $updateValueArray['refund'] = Money::toStorage($validator->validate('refund')); $updateValueArray['refund_note'] = $validator->required()->validate('refund_note'); $updateValueArray['refund_time'] = Time::gmTime(); $updateValueArray['suppliers_refund'] = Money::toStorage($validator->validate('suppliers_refund')); $updateValueArray['suppliers_refund_note'] = $validator->required()->validate('suppliers_refund_note'); break; case 'set_extra_refund': // 权限检查 $this->requirePrivilege('manage_order_goods_update_set_extra_refund'); $updateValueArray['extra_refund'] = Money::toStorage($validator->validate('extra_refund')); $updateValueArray['extra_refund_note'] = $validator->required()->validate('extra_refund_note'); $updateValueArray['extra_refund_time'] = Time::gmTime(); break; default: // 非法的 action goto out; } if (!$this->validate($validator)) { goto out; } // 取 order_goods $orderBasicService = new OrderBasicService(); $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id); if ($orderGoods->isEmpty()) { $this->addFlashMessage('非法订单'); goto out_fail; } // 取得 orderInfo $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']); // 针对不同的 action 做额外不同的工作 $action_note = ''; switch ($action) { case 'set_extra_discount': // 商品只有是未付款状态才可以设置额外优惠 if (OrderGoodsService::OGS_UNPAY != $orderGoods['order_goods_status']) { $this->addFlashMessage('只有未付款订单才可以给予额外优惠'); goto out; } // 额外优惠允许的最大金额 $allowExtraDiscount = $orderGoods['goods_price'] + $orderGoods['shipping_fee'] - $orderGoods['discount']; $maxExtraDiscount = intval($allowExtraDiscount * $f3->get('sysConfig[max_order_goods_extra_discount_rate]')); $maxExtraDiscount = max($maxExtraDiscount, $f3->get('sysConfig[max_order_goods_extra_discount_value]')); $maxExtraDiscount = min($maxExtraDiscount, $allowExtraDiscount); // 额外优惠不能超过商品本身的金额 if ($updateValueArray['extra_discount'] > $maxExtraDiscount) { $this->addFlashMessage('额外优惠不能超过商品总金额 ' . $maxExtraDiscount); goto out; } // 设置额外余额,需要重新计算 order_info 中的值 $diffDiscount = 0; if ($orderGoods->extra_discount != $updateValueArray['extra_discount']) { $diffDiscount = $updateValueArray['extra_discount'] - $orderGoods->extra_discount; } $orderInfo->extra_discount += $diffDiscount; $orderInfo->order_amount -= $diffDiscount; $action_note .= '额外优惠:' . Money::toSmartyDisplay($updateValueArray['extra_discount']) . ","; $action_note .= '优惠说明:' . $updateValueArray['extra_discount_note'] . "\n"; break; case 'set_suppliers_price': $action_note .= '供货价:' . Money::toSmartyDisplay($updateValueArray['suppliers_price']) . ","; $action_note .= '供货快递费:' . Money::toSmartyDisplay($updateValueArray['suppliers_shipping_fee']) . "\n"; break; case 'set_shipping_no': if ($updateValueArray['shipping_id'] > 0) { //取得快递信息 $expressService = new ExpressService(); $expressInfo = $expressService->loadMetaById($updateValueArray['shipping_id']); if ($expressInfo->isEmpty() || ExpressService::META_TYPE != $expressInfo['meta_type']) { $this->addFlashMessage('快递ID非法'); goto out; } $updateValueArray['shipping_name'] = $expressInfo['meta_name']; } else { $updateValueArray['shipping_name'] = null; } $action_note .= '快递公司:' . $updateValueArray['shipping_name'] . "\n"; $action_note .= '快递单号:' . $updateValueArray['shipping_no'] . "\n"; break; case 'set_memo': $action_note .= '客服备注:' . $updateValueArray['memo'] . "\n"; break; case 'set_refund': // 检查订单状态 if (!in_array($orderGoods['order_goods_status'], array(OrderGoodsService::OGS_PAY, OrderGoodsService::OGS_ASKREFUND))) { $this->addFlashMessage('订单状态非法,不能退款'); goto out; } if ($orderGoods['settle_id'] > 0) { $this->addFlashMessage('已经结算的订单不能退款'); goto out; } // 订单设置为 申请退款 $updateValueArray['order_goods_status'] = OrderGoodsService::OGS_ASKREFUND; // 同步更新 order_info 中的 refund 字段 $diffRefund = 0; if ($orderGoods->refund != $updateValueArray['refund']) { $diffRefund = $updateValueArray['refund'] - $orderGoods->refund; } $orderInfo->refund += $diffRefund; // 检查金额,对一些常见错误提出警告 if (0 == $updateValueArray['refund']) { $this->addFlashMessage('警告:你确定给顾客退款金额设置为 ' . Money::toSmartyDisplay($updateValueArray['refund']) . ' ?'); } if (0 == $updateValueArray['suppliers_refund']) { $this->addFlashMessage('警告:你确定供货商给我们退款金额为 ' . Money::toSmartyDisplay($updateValueArray['refund']) . ' ?'); } if ($updateValueArray['refund'] <= $updateValueArray['suppliers_refund']) { $this->addFlashMessage('警告:给顾客退款金额 <= 供货商给我们的退款金额'); } // 日志信息记录 $action_note .= '申请退款' . "\n"; $action_note .= '顾客金额:' . Money::toSmartyDisplay($updateValueArray['refund']) . ","; $action_note .= '顾客说明:' . $updateValueArray['refund_note'] . "\n"; $action_note .= '供货商金额:' . Money::toSmartyDisplay($updateValueArray['suppliers_refund']) . ","; $action_note .= '供货商说明:' . $updateValueArray['suppliers_refund_note'] . "\n"; break; case 'set_extra_refund': // 检查订单状态 if (OrderGoodsService::OGS_UNPAY == $orderGoods['order_goods_status']) { $this->addFlashMessage('订单状态非法,不能退款'); goto out; } $action_note .= '额外退款:' . Money::toSmartyDisplay($updateValueArray['extra_refund']) . ","; $action_note .= '退款说明:' . $updateValueArray['extra_refund_note'] . "\n"; break; default: // 非法的 action goto out; } // 更新订单信息 $orderGoods->copyFrom($updateValueArray); $orderGoods->update_time = Time::gmTime(); $orderGoods->save(); // 更新 order_info 的 update_time 字段 $orderInfo->update_time = Time::gmTime(); $orderInfo->save(); // 添加订单操作日志 $authAdminUser = AuthHelper::getAuthUser(); $orderActionService = new OrderActionService(); $orderActionService->logOrderAction($orderGoods['order_id'], $orderGoods['rec_id'], $orderInfo['order_status'], $orderInfo['pay_status'], $orderGoods['order_goods_status'], $action_note, $authAdminUser['user_name'], 0, $orderInfo['shipping_status']); $this->addFlashMessage('订单信息保存成功'); out: RouteHelper::reRoute($this, RouteHelper::makeUrl('/Order/Goods/Detail', array('rec_id' => $rec_id), true)); return; out_fail: // 失败从这里退出 RouteHelper::reRoute($this, '/Order/Goods/Search', false); }
public function post($f3) { // 权限检查 $this->requirePrivilege('manage_goods_edit_edit_post'); global $smarty; $isCreateGoods = false; // 是否是创建新商品 // 参数验证 $validator = new Validator($f3->get('GET')); $goods_id = $validator->digits()->filter('ValidatorIntValue')->validate('goods_id'); if (!$this->validate($validator)) { goto out_fail_list_goods; } unset($validator); // 用户提交的商品信息做验证 $goods = $f3->get('POST[goods]'); if (empty($goods)) { goto out_fail_validate; } $validator = new Validator($goods); $goodsInfo = array(); //表单数据验证、过滤 $goodsInfo['goods_name'] = $validator->required('商品名不能为空')->validate('goods_name'); $goodsInfo['goods_name_short'] = $validator->required('商品短标题不能为空')->validate('goods_name_short'); $goodsInfo['keywords'] = $validator->validate('keywords'); $goodsInfo['seo_title'] = $validator->validate('seo_title'); $goodsInfo['seo_keyword'] = $validator->validate('seo_keyword'); $goodsInfo['seo_description'] = $validator->validate('seo_description'); $goodsInfo['goods_sn'] = $validator->validate('goods_sn'); $goodsInfo['warehouse'] = $validator->validate('warehouse'); $goodsInfo['shelf'] = $validator->validate('shelf'); $goodsInfo['cat_id'] = $validator->required('商品分类不能为空')->filter('ValidatorIntValue')->validate('cat_id'); // 记录管理员 $authAdminUser = AuthHelper::getAuthUser(); $goodsInfo['admin_user_id'] = $validator->filter('ValidatorIntValue')->validate('admin_user_id'); // 如果没有选择管理员,就用当前管理员 if (empty($goodsInfo['admin_user_id'])) { $goodsInfo['admin_user_id'] = $authAdminUser['user_id']; $goodsInfo['admin_user_name'] = $authAdminUser['user_name']; } else { $adminUserService = new AdminUserService(); $adminUser = $adminUserService->loadAdminById($goodsInfo['admin_user_id']); if ($adminUser->isEmpty()) { $this->addFlashMessage('管理员[' . $goodsInfo['admin_user_id'] . ']不存在'); goto out_fail_validate; } $goodsInfo['admin_user_name'] = $adminUser['user_name']; unset($adminUser); unset($adminUserService); } $goodsInfo['brand_id'] = $validator->filter('ValidatorIntValue')->validate('brand_id'); $goodsInfo['suppliers_id'] = $validator->required('供货商不能为空')->filter('ValidatorIntValue')->validate('suppliers_id'); $goodsInfo['is_alone_sale'] = $validator->filter('ValidatorIntValue')->validate('is_alone_sale'); $goodsInfo['is_best'] = $validator->filter('ValidatorIntValue')->validate('is_best'); $goodsInfo['is_new'] = $validator->filter('ValidatorIntValue')->validate('is_new'); $goodsInfo['is_hot'] = $validator->filter('ValidatorIntValue')->validate('is_hot'); $goodsInfo['is_on_sale'] = $validator->filter('ValidatorIntValue')->validate('is_on_sale'); $goodsInfo['market_price'] = Money::toStorage($validator->validate('market_price')); $goodsInfo['shop_price'] = Money::toStorage($validator->validate('shop_price')); $goodsInfo['shipping_fee'] = Money::toStorage($validator->validate('shipping_fee')); $goodsInfo['shipping_free_number'] = $validator->validate('shipping_free_number'); $goodsInfo['goods_number'] = abs($validator->filter('ValidatorIntValue')->validate('goods_number')); $goodsInfo['virtual_buy_number'] = $validator->filter('ValidatorIntValue')->validate('virtual_buy_number'); $goodsInfo['suppliers_price'] = Money::toStorage($validator->validate('suppliers_price')); $goodsInfo['suppliers_shipping_fee'] = Money::toStorage($validator->validate('suppliers_shipping_fee')); $goodsInfo['sort_order'] = $validator->validate('sort_order'); $goodsInfo['warn_number'] = $validator->filter('ValidatorIntValue')->validate('warn_number'); $goodsInfo['goods_brief'] = @$goods['goods_brief']; //不需要过滤 html $goodsInfo['goods_notice'] = @$goods['goods_notice']; //不需要过滤 html $goodsInfo['goods_after_service'] = @$goods['goods_after_service']; //不需要过滤 html $goodsInfo['seller_note'] = $validator->validate('seller_note'); $goodsInfo['system_tag_list'] = Utils::makeTagString(@$goods['system_tag_list']); // 生成系统的 tag string $goodsInfo['update_time'] = Time::gmTime(); // 商品的更新时间 $goodsInfo['goods_desc'] = @$goods['goods_desc']; //不需要过滤 html if (!$this->validate($validator)) { goto out_fail_validate; } // 某些时候,我们不允许编辑直接粘贴别人网站的图片上来,所以我们需要过滤图片的域名 $goodsDescAllowImageDomainArray = $f3->get('sysConfig[goods_desc_allow_image_domain_array]'); if ($goodsDescAllowImageDomainArray && is_array($goodsDescAllowImageDomainArray) && !empty($goodsDescAllowImageDomainArray)) { $patternMatch = array(); preg_match_all('/<img(.*?)src="(.*?)"(.*?)\\/?>/', $goodsInfo['goods_desc'], $patternMatch, PREG_SET_ORDER); // 检查每一个图片 foreach ($patternMatch as $matchItem) { $imageUrl = $matchItem[2]; $urlInfo = parse_url($imageUrl); if (!in_array(@$urlInfo['host'], $goodsDescAllowImageDomainArray)) { $this->addFlashMessage('商品详情非法图片 ' . $imageUrl); goto out_fail_validate; } } } // 写入到数据库 unset($goods); $goodsBasicService = new GoodsBasicService(); $goods = $goodsBasicService->loadGoodsById($goods_id); // 判断是否是新建商品 $isCreateGoods = $goods->isEmpty(); if ($isCreateGoods) { // 权限检查 $this->requirePrivilege('manage_goods_create'); $goodsInfo['add_time'] = Time::gmTime(); } $post_goods_sn = $validator->validate('goods_sn'); if ($isCreateGoods && !Utils::isBlank($post_goods_sn)) { $goodsInfo['goods_sn'] = $post_goods_sn; } $goods->copyFrom($goodsInfo); $goods->save(); // 新商品需要自动生成 goods_sn if ($isCreateGoods && Utils::isBlank($post_goods_sn)) { $goods->goods_sn = $f3->get('sysConfig[goods_sn_prefix]') . $goods['goods_id']; $goods->save(); } // 取得供货商信息 $supplierName = ''; if (!empty($goods['suppliers_id'])) { $supplierUserService = new SupplierUserService(); $supplierInfo = $supplierUserService->loadSupplierById($goods['suppliers_id']); if (!$supplierInfo->isEmpty()) { $supplierName = $supplierInfo['suppliers_name']; } } // 记录商品编辑日志 $goodsLogContent = '商品编辑:[' . $goods['admin_user_id'] . ']' . $goods['admin_user_name'] . "\n" . '上架状态:' . ($goods['is_on_sale'] > 0 ? '已上架' : '未上架') . "\n" . '销售价:' . Money::toSmartyDisplay($goods['shop_price']) . ' 供货价:' . Money::toSmartyDisplay($goods['suppliers_price']) . "\n" . '快递费:' . Money::toSmartyDisplay($goods['shipping_fee']) . ' 供货快递费:' . Money::toSmartyDisplay($goods['suppliers_shipping_fee']) . "\n" . ($goods['shipping_free_number'] > 0 ? '' . $goods['shipping_free_number'] . "件免邮\n" : '') . '商品排序:' . $goods['sort_order'] . "\n" . '系统Tag:' . $goods['system_tag_list'] . "\n" . '供货商:[' . $goods['suppliers_id'] . ']' . $supplierName; $goodsLogService = new GoodsLogService(); $goodsLogService->addGoodsLog($goods['goods_id'], $authAdminUser['user_id'], $authAdminUser['user_name'], $isCreateGoods ? '新建商品' : static::$goodsLogDesc, $goodsLogContent); // 成功,显示商品详情 $this->addFlashMessage('商品信息保存成功'); //清除缓存,确保商品显示正确 ClearHelper::clearGoodsCacheById($goods->goods_id); RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Edit', array('goods_id' => $goods->goods_id), true)); return; // 参数验证失败 out_fail_validate: if (!$goods_id) { // 新建商品验证失败 RouteHelper::reRoute($this, '/Goods/Create'); return; } $smarty->assign('goods', $goodsInfo); $smarty->display('goods_edit_edit.tpl'); return; out_fail_list_goods: RouteHelper::reRoute($this, '/Goods/Search'); }
private function outputDataRow($activeSheet, $rowIndex, $dataRowItem, $excludeKeyArray = null) { // 代表价格的列,需要特殊处理显示格式 $priceColumnArray = array('goods_price', 'shipping_fee', 'discount', 'extra_discount', 'refund', 'extra_refund', 'surplus', 'bonus', 'cps_amount', 'cps_fee', 'cps_extra'); // 输出数据 $colIndex = 1; foreach ($this->filterArray as $key => $value) { if (!array_key_exists($key, $dataRowItem) || !empty($excludeKeyArray) && in_array($key, $excludeKeyArray)) { $colIndex++; continue; } $cellValue = isset($dataRowItem[$key]) ? $dataRowItem[$key] : ''; if (in_array($key, $priceColumnArray)) { // 金额需要做转化 $cellValue = Money::toSmartyDisplay($cellValue); $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue); } else { $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue); $activeSheet->getCellByColumnAndRow($colIndex, $rowIndex)->setDataType(\PHPExcel_Cell_DataType::TYPE_STRING); } // 未付款订单,用淡蓝色标注 if (array_key_exists('order_goods_status', $dataRowItem) && 0 == $dataRowItem['order_goods_status']) { $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FF49AFCD'); } // 退款订单,用红色标注 (退款订单) if (array_key_exists('order_goods_status', $dataRowItem) && $dataRowItem['order_goods_status'] > 1) { $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFFF0000'); } $colIndex++; } }
/** * 下载 拣货单 * * @param $f3 * @param $validator */ public function downloadJianHuo($f3, $validator) { $outputColumnArray = array('warehouse' => '仓库', 'shelf' => '货架', 'goods_sn' => '货号', 'goods_name' => '商品名', 'goods_attr' => '属性规格', 'goods_number' => '数量', 'suppliers_price' => '供货单价', 'total_suppliers_price' => '供货总价', 'total_suppliers_shipping_fee' => '供货快递'); $outputColumnMoneyArray = array('suppliers_price', 'total_suppliers_price', 'total_suppliers_shipping_fee'); //表单查询 $searchFormQuery = array(); $searchFormQuery['og.goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id'); //付款时间 $payTimeStartStr = $validator->validate('pay_time_start'); $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null; $payTimeEndStr = $validator->validate('pay_time_end'); $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null; $searchFormQuery['oi.pay_time'] = array($payTimeStart, $payTimeEnd); // 快递信息 $expressType = $validator->digits()->min(0)->filter('ValidatorIntValue')->validate('expressType'); switch ($expressType) { case 1: $searchFormQuery['og.shipping_id'] = 0; break; case 2: $searchFormQuery['og.shipping_id'] = array('>', 0); break; default: break; } if (!$this->validate($validator)) { goto out_fail; } if (Utils::isBlank($searchFormQuery['og.goods_id']) && Utils::isBlank($payTimeStart)) { $this->addFlashMessage('查询参数非法'); goto out_fail; } // 构造查询条件 $authSupplierUser = AuthHelper::getAuthUser(); $searchFormQuery['og.suppliers_id'] = $authSupplierUser['suppliers_id']; $searchParamArray = array(); $searchParamArray[] = array('oi.order_id = og.order_id'); //供货商,只查看有效订单,其它订单不显示 $searchParamArray[] = array('og.order_goods_status > 0'); // 表单查询 $searchParamArray = array_merge($searchParamArray, QueryBuilder::buildSearchParamArray($searchFormQuery)); $orderGoodsArray = SearchHelper::search(SearchHelper::Module_OrderGoodsOrderInfo, 'og.warehouse, og.shelf, og.goods_id, og.goods_sn, og.goods_attr, sum(og.goods_number) as goods_number, sum(og.suppliers_price * og.goods_number) as total_suppliers_price, sum(og.suppliers_shipping_fee) as total_suppliers_shipping_fee', $searchParamArray, array(array('og.warehouse', 'asc'), array('og.shelf', 'asc')), 0, $f3->get('sysConfig[max_query_record_count]'), 'og.warehouse, og.shelf, og.goods_id, og.goods_sn, og.goods_attr'); // 没有数据,退出 if (empty($orderGoodsArray)) { goto out; } // 查询订单对应的商品 $goodsIdArray = array(); foreach ($orderGoodsArray as $orderGoodsItem) { $goodsIdArray[] = $orderGoodsItem['goods_id']; } $goodsIdArray = array_unique($goodsIdArray); $goodsArray = SearchHelper::search(SearchHelper::Module_Goods, 'goods_id, goods_name_short, suppliers_price', array(array(QueryBuilder::buildInCondition('goods_id', $goodsIdArray, \PDO::PARAM_INT))), null, 0, $f3->get('sysConfig[max_query_record_count]')); $goodsIdToGoodsMap = array(); foreach ($goodsArray as $goodsItem) { $goodsIdToGoodsMap[$goodsItem['goods_id']] = $goodsItem; } require_once PROTECTED_PATH . '/Vendor/PHPExcel/Settings.php'; // 设置Excel缓存,防止数据太多拖死了程序 \PHPExcel_Settings::setCacheStorageMethod(\PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp); // 导出为 Excel 格式 $objPHPExcel = new \PHPExcel(); // 设置工作 sheet $objPHPExcel->setActiveSheetIndex(0); $activeSheet = $objPHPExcel->getActiveSheet(); // 格式化数据 $rowIndex = 1; $lastWarehouseShelf = null; $orderGoodsArraySize = count($orderGoodsArray); // 输出头部信息 $colIndex = 1; foreach ($outputColumnArray as $value) { $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $value); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFont()->setBold(true); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID); $activeSheet->getStyleByColumnAndRow($colIndex, $rowIndex)->getFill()->getStartColor()->setARGB('FFB0B0B0'); $colIndex++; } $rowIndex++; // 换行 for ($orderGoodsIndex = 0; $orderGoodsIndex < $orderGoodsArraySize; $orderGoodsIndex++) { // 取得这行数据 $orderGoodsItem = $orderGoodsArray[$orderGoodsIndex]; // 填入商品数据 $orderGoodsItem['goods_name'] = $goodsIdToGoodsMap[$orderGoodsItem['goods_id']]['goods_name_short']; $orderGoodsItem['suppliers_price'] = $goodsIdToGoodsMap[$orderGoodsItem['goods_id']]['suppliers_price']; if ($lastWarehouseShelf != $orderGoodsItem['warehouse'] . '$' . $orderGoodsItem['shelf']) { $lastWarehouseShelf = $orderGoodsItem['warehouse'] . '$' . $orderGoodsItem['shelf']; // 不同的取货地点,需要特殊处理 $rowIndex += 2; // 跳过 2 行 } // 输出一行数据 $colIndex = 1; foreach ($outputColumnArray as $key => $value) { $cellValue = isset($orderGoodsItem[$key]) ? $orderGoodsItem[$key] : ''; if (!in_array($key, $outputColumnMoneyArray)) { $activeSheet->getCellByColumnAndRow($colIndex, $rowIndex)->setDataType(\PHPExcel_Cell_DataType::TYPE_STRING); } else { // 转换价格显示 $cellValue = Money::toSmartyDisplay($cellValue); } $activeSheet->setCellValueByColumnAndRow($colIndex, $rowIndex, $cellValue); $colIndex++; } $rowIndex++; // 换行 } $fileName = '拣货单_' . $searchFormQuery['og.goods_id'] . '_' . Time::gmTimeToLocalTimeStr($payTimeStart, 'Y-m-d_H-i-s') . '__' . Time::gmTimeToLocalTimeStr($payTimeEnd, 'Y-m-d_H-i-s'); // 输出为 Excel5 格式 $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel); header('Content-Type: application/vnd.ms-excel'); if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) { header('Content-Disposition: attachment; filename="' . urlencode($fileName) . '.xls"'); } else { header('Content-Disposition: attachment; filename="' . $fileName . '.xls"'); } header('Cache-Control: max-age=0'); $objWriter->save('php://output'); //输出到浏览器 die; out: echo "没有数据"; die; out_fail: // 失败,打印错误消息 $flashMessageArray = $this->flashMessageArray; foreach ($flashMessageArray as $flashMessage) { echo $flashMessage . '<br />'; } }
/** * 正确显示商品价格,千分位价格显示 比如 52.10 显示为 52.1 , 52.00 显示为 52 */ function smarty_helper_modifier_money_display($price) { return \Core\Helper\Utility\Money::toSmartyDisplay($price); }
private function getGoodsItemXml($goodsItem, $goodsIdToGalleryArray) { // 截取描述,不能太长 $goodsItem['goods_desc'] = mb_substr($goodsItem['goods_name'] . ' ' . strip_tags($goodsItem['goods_desc']), 0, 1000); // 截取商品标题,标题不能太长了 $goodsItem['goods_name'] = mb_substr($goodsItem['goods_name'], 0, 60); $goodsViewUrl = RouteHelper::makeUrl('/Goods/View', array('goods_id' => $goodsItem['goods_id']), false, true); // 增加额外的链接参数 $goodsViewUrl .= EtaoFeedPlugin::getOptionValue('etaofeed_goods_url_extra_param'); // 处理图片列表 $goodsGalleryArray = array(); if (array_key_exists($goodsItem['goods_id'], $goodsIdToGalleryArray)) { $goodsGalleryArray = $goodsIdToGalleryArray[$goodsItem['goods_id']]; } $goodsItemImageXml = ''; if (!empty($goodsGalleryArray)) { $goodsItemImageXml = '<image is_default="true">' . RouteHelper::makeImageUrl($goodsGalleryArray[0]['img_original']) . '</image>'; array_shift($goodsGalleryArray); // 去掉第一个图片 $goodsItemImageXml .= '<more_images>'; // 图片集中的图片 foreach ($goodsGalleryArray as $goodsGalleryItem) { $goodsItemImageXml .= '<img>' . RouteHelper::makeImageUrl($goodsGalleryItem['img_original']) . '</img>'; } $goodsItemImageXml .= '</more_images>'; } // 转换数据显示 $goodsItem['shop_price'] = Money::toSmartyDisplay($goodsItem['shop_price']); $goodsItem['shipping_fee'] = Money::toSmartyDisplay($goodsItem['shipping_fee']); $goodsItemXml = <<<XML <item> \t<seller_id><![CDATA[{$this->sellerId}]]></seller_id> \t<outer_id>{$goodsItem['goods_id']}</outer_id> \t<title><![CDATA[{$goodsItem['goods_name']}]]></title> \t<product_id>{$goodsItem['goods_sn']}</product_id> \t<type>fixed</type> \t<available>1</available> \t<price>{$goodsItem['shop_price']}</price> \t<desc><![CDATA[{$goodsItem['goods_desc']}]]></desc> \t{$goodsItemImageXml} \t<scids>{$goodsItem['cat_id']}</scids> \t<post_fee>{$goodsItem['shipping_fee']}</post_fee> \t<href><![CDATA[{$goodsViewUrl}]]></href> </item> XML; return $goodsItemXml; }
private function getGoodsItemXml($index, $goodsItem, $goodsIdToGalleryArray) { global $f3; static $buyNotice = "【下单说明】请在下单时留言注明尺码准确填写姓名、电话和收件地址!\n【发货说明】下单后48小时内发货,快递3-5天左右到达,节假日顺延。偏远地区需要补10元邮费。\n【关于尺寸】因测量手法问题,测量数据可能存在2-3CM误差,还请见谅!\n【关于色差】颜色因场景拍摄及电脑显示有差异均属于正常,不属于质量问题。图色显示与实物颜色我们保证以最接近实物的颜色上传。\n【关于签收】请务必本人签收。验货后,如商品有任何破损问题请当快递员面拒收!"; $siteName = $f3->get('sysConfig[site_name]'); $goodsViewUrl = RouteHelper::makeUrl('/Goods/View', array('goods_id' => $goodsItem['goods_id']), false, true); $goodsViewUrl = RouteHelper::addParam($goodsViewUrl, array('utm_source' => 'gouwuke')); $goodsImageUrlList = '<picurls>'; $goodsGalleryArray = @$goodsIdToGalleryArray[$goodsItem['goods_id']]; if (!empty($goodsGalleryArray)) { foreach ($goodsGalleryArray as $goodsGalleryItem) { $goodsImageUrlList .= '<picurllist>'; $goodsImageUrlList .= '<picurl><![CDATA[' . RouteHelper::makeImageUrl($goodsGalleryItem['img_url']) . ']]></picurl>'; $goodsImageUrlList .= '<bigpicurl><![CDATA[' . RouteHelper::makeImageUrl($goodsGalleryItem['img_original']) . ']]></bigpicurl>'; $goodsImageUrlList .= '</picurllist>'; } } $goodsImageUrlList .= '</picurls>'; // 取得商品的分类层级 $goodsCategoryLevelArray = array(); $categoryLevel = 5; // 最多取 5 层分类 $currentCategoryId = $goodsItem['cat_id']; for (; $categoryLevel > 0; $categoryLevel--) { $category = $this->goodsCategoryService->loadCategoryById($currentCategoryId, 1800); if ($category->isEmpty()) { break; } array_unshift($goodsCategoryLevelArray, $category); if ($category['parent_meta_id'] <= 0) { break; } $currentCategoryId = $category['parent_meta_id']; } $goodsCategoryLevelStr = ''; foreach ($goodsCategoryLevelArray as $goodsCategoryItem) { $goodsCategoryLevelStr .= $goodsCategoryItem['meta_name'] . ' > '; } $goodsCategoryLevelStr .= '当前商品'; // 转换价格显示 $goodsItem['market_price'] = Money::toSmartyDisplay($goodsItem['market_price']); $goodsItem['shop_price'] = Money::toSmartyDisplay($goodsItem['shop_price']); $xmlitem = <<<XMLITEM \t<urlset> \t <ident><![CDATA[{$this->siteIdentify}_{$goodsItem['goods_id']}]]></ident> \t <productname><![CDATA[{$goodsItem['goods_name']}]]></productname> \t <refprice>{$goodsItem['market_price']}</refprice> <price_1>{$goodsItem['shop_price']}</price_1> <zhekou_price><![CDATA[]]></zhekou_price> <zhekou><![CDATA[]]></zhekou> <ifcuxiao><![CDATA[false]]></ifcuxiao> <quehuo><![CDATA[false]]></quehuo> {$goodsImageUrlList} \t <url><![CDATA[{$goodsViewUrl}]]></url> \t <shortintro><![CDATA[{$goodsItem['goods_name']}]]></shortintro> \t <shortintrohtml><![CDATA[{$buyNotice}]]></shortintrohtml> \t <orifenlei><![CDATA[{$goodsCategoryLevelStr}]]></orifenlei> \t <pinpai><![CDATA[]]></pinpai> \t <color><![CDATA[]]></color> <chandi><![CDATA[]]></chandi> </urlset> XMLITEM; return $xmlitem; }
public function post($f3) { // 权限检查 $this->requirePrivilege('manage_goods_edit_edit_post'); $goodsLogContent = ''; // 参数验证 $validator = new Validator($f3->get('GET')); $goods_id = $validator->required()->digits()->min(1)->validate('goods_id'); if (!$this->validate($validator)) { goto out_fail_list_goods; } unset($validator); $goodsBasicService = new GoodsBasicService(); $goods = $goodsBasicService->loadGoodsById($goods_id, 1); if ($goods->isEmpty()) { $this->addFlashMessage('商品 id[' . $goods_id . '] 非法'); goto out_fail_list_goods; } // POST 参数验证 $validator = new Validator($f3->get('POST')); $goodsSpecNameArray = $validator->validate('goodsSpecNameArray'); $goodsSpecValue1Array = $validator->validate('goodsSpecValue1Array'); $goodsSpecValue2Array = $validator->validate('goodsSpecValue2Array'); $goodsSpecValue3Array = $validator->validate('goodsSpecValue3Array'); $goodsNumberArray = $validator->validate('goodsNumberArray'); $goodsSpecAddPriceArray = $validator->validate('goodsSpecAddPriceArray'); $goodsSnArray = $validator->validate('goodsSnArray'); $imgIdArray = $validator->validate('imgIdArray'); if (empty($goodsSpecValue1Array)) { goto save_spec; } // 检查,商品属性名不能为空 foreach ($goodsSpecNameArray as $goodsSpecName) { if (!empty($goodsSpecName)) { break; } $this->addFlashMessage('商品属性名不能为空'); goto out_fail_edit_spec; } // 商品选项中不能有特殊符号 $valueArray = array_merge($goodsSpecValue1Array, $goodsSpecValue2Array, $goodsSpecValue3Array); foreach ($valueArray as $valueItem) { if (empty($valueItem)) { continue; } // 商品规格不允许有特殊符号 if (preg_match('#[,\\\\t\\s\\n\\+\\?\\^~!%/$]+#', $valueItem)) { $this->addFlashMessage('商品选项不能有特殊符号: 逗号、空格、回车、\\、? 等 ...'); goto out_validate_fail; } } // 做数据格式转换,商品库存 foreach ($goodsNumberArray as &$number) { $number = abs(intval($number)); } unset($number); // 做数据格式转换,商品规格对应的加价 foreach ($goodsSpecAddPriceArray as &$add_price) { $add_price = Money::toStorage(abs(floatval($add_price))); } unset($add_price); if (!$this->validate($validator)) { goto out_reroute; } save_spec: $goodsSpecService = new GoodsSpecService(); $goodsSpecService->initWithData($goodsSpecNameArray, $goodsSpecValue1Array, $goodsSpecValue2Array, $goodsSpecValue3Array, $goodsNumberArray, $goodsSpecAddPriceArray, $goodsSnArray, $imgIdArray); // 保存数据 $goodsSpecService->saveGoodsSpec($goods_id); $this->addFlashMessage('更新商品规格成功'); out: // 正常退出 $goodsSpecNameArray = is_array($goodsSpecNameArray) ? $goodsSpecNameArray : array(); $goodsLogContent .= '属性名:' . implode(',', $goodsSpecNameArray) . "\n"; $valueCount = count($goodsSpecValue1Array); for ($valueIndex = 0; $valueIndex < $valueCount; $valueIndex++) { $goodsLogContent .= '选择:' . @$goodsSpecValue1Array[$valueIndex] . ',' . @$goodsSpecValue2Array[$valueIndex] . ',' . @$goodsSpecValue3Array[$valueIndex] . ',' . '库存:' . @$goodsNumberArray[$valueIndex] . ',' . '加价:' . Money::toSmartyDisplay(@$goodsSpecAddPriceArray[$valueIndex]) . ',' . 'SN:' . @$goodsSnArray[$valueIndex] . ',' . 'image:' . @$imgIdArray[$valueIndex] . ',' . "\n"; } $authAdminUser = AuthHelper::getAuthUser(); $goodsLogService = new GoodsLogService(); $goodsLogService->addGoodsLog($goods_id, $authAdminUser['user_id'], $authAdminUser['user_name'], '商品规格', $goodsLogContent); //清除缓存,确保商品显示正确 ClearHelper::clearGoodsCacheById($goods_id); out_reroute: RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Spec', array('goods_id' => $goods_id), true)); return; out_fail_list_goods: RouteHelper::reRoute($this, '/Goods/Search'); return; out_validate_fail: global $smarty; $smarty->display('goods_edit_spec.tpl'); return; out_fail_edit_spec: RouteHelper::reRoute($this, RouteHelper::makeUrl('/Goods/Edit/Spec', array('goods_id' => $goods->goods_id), true)); }
/** * 给用户余额充值 * @param $f3 */ public function Charge($f3) { // 权限检查 $this->requirePrivilege('manage_account_user_charge'); $validator = new Validator($f3->get('POST')); $user_id = $validator->required()->digits()->validate('user_id'); $chargeMoney = Money::toStorage($validator->validate('chargeMoney')); $chargeMoneyDesc = $validator->validate('chargeMoneyDesc'); if (!$this->validate($validator)) { goto out; } if (0 == $chargeMoney) { $this->addFlashMessage('充值为0,不操作'); goto out; } // 加载用户信息 $userBasicService = new UserBasicService(); $userInfo = $userBasicService->loadUserById($user_id); if ($userInfo->isEmpty()) { $this->addFlashMessage('用户ID非法[' . $user_id . ']'); goto out; } // 当前操作的管理员 $authAdminUser = AuthHelper::getAuthUser(); // 给用户充值 $accountLog = new AccountLog(); $accountLog->logChange($user_id, $chargeMoney, 0, 0, 0, '管理员[' . $authAdminUser['user_name'] . ']充值[' . Money::toSmartyDisplay($chargeMoney) . ']元' . "\n" . $chargeMoneyDesc, $chargeMoney > 0 ? AccountLog::ACT_SAVING : AccountLog::ACT_DRAWING, $authAdminUser['user_id']); $this->addFlashMessage('充值 [' . Money::toSmartyDisplay($chargeMoney) . '] 元成功'); out: RouteHelper::reRoute($this, RouteHelper::getRefer(), false); }