lqmac 4 months ago
parent 1ea1fe4144
commit f1148fc5b3
  1. 1
      app/admin/controller/Goods.php
  2. 143
      app/api/controller/Goods.php
  3. 5
      app/common.php
  4. 2
      app/common/model/Goods.php
  5. 8
      app/job/service/goods/Collector.php
  6. 1
      app/job/service/goods/GoodsUpdateImport.php

@ -353,6 +353,7 @@ class Goods extends Controller
['delivery_time'=>'发货时效(0:24小时 1:48小时 2:72小时 3:7天内 4:15天内 5:30天内 6:45天内 填写其中一项)'],
['is_check'=>'是否审单(是填1 否填0)'],
['is_use_jd_stock'=>'是否使用京东库存(是填1 否填0)'],
['video_id'=>'是否覆盖商品(是填1 否填0)'],
];
downLoadExcel('导出数据-'.date('Y-m-d', time()),$titles,$data['data']);

@ -25,6 +25,149 @@ use EasyWeChat\Factory;
*/
class Goods extends Controller
{
public function pay(){
// $merchantCode = '123456789900081';
// $terminalCode = '00810001';
// $originalOrderId = '20190306113204000017183219';
// $data = array(
// 'merchantCode'=>$merchantCode,
// 'terminalCode'=>$terminalCode,
// 'originalOrderId'=>$originalOrderId
// );
//$ret = $this->unify(date("YmdHis").mt_rand(1000,9999), "1");
$ret = $this->tradeQuery(date("YmdHis").mt_rand(1000,9999));
return $this->renderSuccess([ 'ret' => $ret]);
}
/**
* 支付成功后的异步通知
* @return bool
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
public function notify(): bool
{
if (!$this->getApp()->notify()) {
$this->setError($this->getApp()->getError());
return false;
}
return true;
}
/**
* 微信支付退款API
* @param string $outTradeNo 第三方交易单号
* @param string $refundAmount 退款金额
* @param array $extra 附加数据 (需要携带订单付款总金额)
* @return bool
* @throws BaseException
*/
public function refund(string $outTradeNo, string $refundAmount, array $extra = []): bool
{
$tradeQuery_url = "https://test-api-open.chinaums.com/v1/netpay/refund";
//$order_url = "https://api-mop.chinaums.com/v1/netpay/refund";
$mid = "898340149000005";
$tid = "88880001";
$subAppId = "wxa3127ed5c3542a28";
$subOpenId = "oxeW66xXaOt4ErNCFTIDn90Zu_FI";
$params = [
"requestTimestamp" => date("Y-m-d H:i:s"),
"merOrderId" => $outTradeNo,//date("YmdHis").mt_rand(1000,9999),
"mid" => $mid,
"tid" => $tid,
"targetOrderId" => $tid,
"refundAmount" => $tid,
"refundOrderId" => $tid,
"platformAmount" => $tid,
"refundDesc" => $tid,
];
$authorization = $this->getAuthorization($params);
$headers = ["Authorization:".$authorization];
$ret = httpRequest($order_url, "POST", json_encode($params), $headers, true);
return $ret;
}
/**
* 交易查询 (主动查询订单支付状态)
* @param string $outTradeNo 交易订单号
* @return array|null
* @throws BaseException
*/
public function tradeQuery(string $outTradeNo): ?array
{
$tradeQuery_url = "https://test-api-open.chinaums.com/v1/netpay/query";
//$order_url = "https://api-mop.chinaums.com/v1/netpay/query";
$mid = "898340149000005";
$tid = "88880001";
$subAppId = "wxa3127ed5c3542a28";
$subOpenId = "oxeW66xXaOt4ErNCFTIDn90Zu_FI";
$params = [
"requestTimestamp" => date("Y-m-d H:i:s"),
"merOrderId" => $outTradeNo,//date("YmdHis").mt_rand(1000,9999),
"mid" => $mid,
"tid" => $tid,
];
$authorization = $this->getAuthorization($params);
$headers = ["Authorization:".$authorization];
$ret = httpRequest($order_url, "POST", json_encode($params), $headers, true);
return $ret;
}
/**
* 统一下单API
* @param string $outTradeNo 交易订单号
* @param string $totalFee 实际付款金额
* @param array $extra 附加的数据 (需要携带openid)
* @return bool
* @throws BaseException
*/
public function unify(string $outTradeNo, string $totalFee, array $extra = []): bool{
$order_url = "https://test-api-open.chinaums.com/v1/netpay/wx/unified-order";
//$order_url = "https://api-mop.chinaums.com/v1/netpay/wx/unified-order";
$mid = "898340149000005";
$tid = "88880001";
$subAppId = "wxa3127ed5c3542a28";
$subOpenId = "oxeW66xXaOt4ErNCFTIDn90Zu_FI";
$params = [
"requestTimestamp" => date("Y-m-d H:i:s"),
"merOrderId" => $outTradeNo,//date("YmdHis").mt_rand(1000,9999),
"mid" => $mid,
"tid" => $tid,
"subAppId" => $subAppId,
"subOpenId" => $subOpenId,
"tradeType" => "MINI",
"notifyUrl" => "回调地址",
"orderDesc" => "账单描述",
"totalAmount" => $totalFee,
"divisionFlag" => true,//分账标记
"platformAmount" => true,//平台商户分 账金额
"subOrders" => [
[
"mid" => "111",
"totalAmount" => 1,
]
],
];
$authorization = $this->getAuthorization($params);
$headers = ["Authorization:".$authorization];
$ret = httpRequest($order_url, "POST", json_encode($params), $headers, true);
return $ret;
}
public function getAuthorization($data){
$appid = 'f0ec96ad2c3848b5b810e7aadf369e2f';
$appkey = '775481e2556e4564985f5439a5e6a277';
$timestamp = date("YmdHis",time());
$nonce = md5(uniqid((string)microtime(true),true));
$body = json_encode($data);
//echo $body;
$str = bin2hex(hash('sha256', $body, true));
$signature = base64_encode(hash_hmac('sha256', "$appid$timestamp$nonce$str", $appkey, true));
$authorization = "OPEN-BODY-SIG AppId=$appid, Timestamp=$timestamp, Nonce=$nonce, =$signature";
return $authorization;
}
/**
* 商品列表
* @return Json

@ -578,8 +578,11 @@ function httpRequest($url, $method="GET", $postfields = null, $headers = array()
$requestinfo = curl_getinfo($ci);
$http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
$curl_error = curl_errno($ci);
var_dump($response);
var_dump($curl_error);
//exit;
if($curl_error){
Log::error("ERROR_CODE:{$curl_error} | URL:".$url.' | postfields:'.json_encode($postfields),'curl_error');
Log::error("ERROR_CODE:{$curl_error} | URL:".$url.' | postfields:'.json_encode($postfields));
//sys_log("ERROR_CODE:{$curl_error} | URL:".$url.' | postfields:'.json_encode($postfields),'curl_error');
//\app\common\util\ErrorAlert::curlWarning($url,$curl_error);
}

@ -209,7 +209,7 @@ class Goods extends BaseModel
// 执行查询
$list = $query
->alias($this->name)
->field(['goods.goods_id', 'goods.goods_name', 'cmmdty_model', 'remark', 'cost_price_min', 'stock_total', 'is_check', 'goods_price_min','goods_no','goods_source','delivery_time','delivery_id','status','link','link_other','channel','is_use_jd_stock'])
->field(['goods.goods_id', 'goods.goods_name', 'cmmdty_model', 'remark', 'cost_price_min', 'stock_total', 'is_check', 'goods_price_min','goods_no','goods_source','delivery_time','delivery_id','status','link','link_other','channel','is_use_jd_stock','video_id'])
->where('is_delete', '=', 0)
->order($sort)
->paginate($listRows);

@ -281,9 +281,12 @@ class Collector extends BaseService
return true;
}
//新阙通信的抓取过了,就不抓取了;京东价拖抓取过了就不抓取了
if (($goods['channel'] == 'xqtx' && $goods['content']) || $goods->goods_no_other) {
return true;
if (isset($form['is_cover']) && $form['is_cover'] == 0) {
if (($goods['channel'] == 'xqtx' && $goods['content']) || $goods->goods_no_other) {
return true;
}
}
try {
// 采集第三方商品数据
@ -382,6 +385,7 @@ class Collector extends BaseService
// var_dump($goodsSku);
// exit();
$model->transaction(function () use ($form, $data, $original, $goodsSku) {
$data['update_time'] = time();
// 添加商品
GoodsModel::where('goods_id', $form['goods_id'])->update($data);
// 新增商品与图片关联

@ -132,6 +132,7 @@ class GoodsUpdateImport extends BaseService
'delivery_time' => $original['K'] ?? 2,
'is_check' => $original['L'] ?? 0,
'is_use_jd_stock' => $original['M'] ?? 0,
'is_cover' => $original['N'] ?? 0,//是否覆盖
];
return $data;

Loading…
Cancel
Save