初始上传
This commit is contained in:
282
addon/shopcomponent/model/Category.php
Executable file
282
addon/shopcomponent/model/Category.php
Executable file
@@ -0,0 +1,282 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\shopcomponent\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use think\facade\Cache;
|
||||
|
||||
class Category extends BaseModel
|
||||
{
|
||||
private $statusName = [
|
||||
'0' => '待提交',
|
||||
'1' => '审核成功',
|
||||
'9' => '审核拒绝'
|
||||
];
|
||||
private $type = [
|
||||
'0' => '不需要',
|
||||
'1' => '需要',
|
||||
'2' => '可选'
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取类目列表
|
||||
* @param array $condition
|
||||
* @param bool $field
|
||||
* @param string $order
|
||||
* @param int $page
|
||||
* @param int $list_rows
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @return array
|
||||
*/
|
||||
public function getCategoryPageList($condition = [], $field = true, $order = '', $page = 1, $list_rows = PAGE_LIST_ROWS, $alias = 'a', $join = [])
|
||||
{
|
||||
$check_condition = array_column($condition, 2, 0);
|
||||
$site_id = $check_condition['site_id'] ?? 0;
|
||||
|
||||
$site_id_index = array_search('site_id', array_keys(array_column($condition, 2, 0)));
|
||||
unset($condition[ $site_id_index ]);
|
||||
|
||||
$data = model('shopcompoent_category')->pageList($condition, $field, $order, $page, $list_rows, $alias, $join);
|
||||
if (!empty($data[ 'list' ])) {
|
||||
foreach ($data[ 'list' ] as $k => $item) {
|
||||
$audit_info = model('shopcompoent_category_audit')->getInfo([ [ 'site_id', '=', $site_id ], [ 'third_cat_id', '=', $item[ 'third_cat_id' ] ] ]);
|
||||
if (empty($audit_info)) {
|
||||
$audit_info = [
|
||||
'certificate' => '',
|
||||
'qualification_pics' => '',
|
||||
'audit_id' => '',
|
||||
'audit_time' => 0,
|
||||
'status' => 0,
|
||||
'reject_reason' => ''
|
||||
];
|
||||
}
|
||||
|
||||
$item = array_merge($item, $audit_info);
|
||||
$data[ 'list' ][ $k ] = $item;
|
||||
|
||||
if ($item[ 'audit_time' ] > 0 && $item[ 'status' ] == 0) {
|
||||
$data[ 'list' ][ $k ][ 'status_name' ] = '审核中';
|
||||
} else if ($item[ 'qualification_type' ] == 0 && $item[ 'product_qualification_type' ] == 0) {
|
||||
$data[ 'list' ][ $k ][ 'status_name' ] = '--';
|
||||
} else {
|
||||
$data[ 'list' ][ $k ][ 'status_name' ] = $this->statusName[ $item[ 'status' ] ] ?? '';
|
||||
}
|
||||
$data[ 'list' ][ $k ][ 'create_time' ] = $item[ 'create_time' ] > 0 ? time_to_date($item[ 'create_time' ]) : '--';
|
||||
$data[ 'list' ][ $k ][ 'audit_time' ] = $item[ 'audit_time' ] > 0 ? time_to_date($item[ 'audit_time' ]) : '--';
|
||||
$data[ 'list' ][ $k ][ 'leimu' ] = $item[ 'first_cat_name' ] . '>' . $item[ 'second_cat_name' ] . '>' . $item[ 'third_cat_name' ];
|
||||
$data[ 'list' ][ $k ][ 'product_qualification_type_name' ] = $this->type[ $item[ 'product_qualification_type' ] ] ?? '';
|
||||
$data[ 'list' ][ $k ][ 'qualification_type_name' ] = $this->type[ $item[ 'qualification_type' ] ] ?? '';
|
||||
$data[ 'list' ][ $k ][ 'license' ] = Cache::get('license_' . $item[ 'third_cat_id' ]);
|
||||
$data[ 'list' ][ $k ][ 'reject_reason' ] = str_replace('https://developers.weixin.qq.com/miniprogram/dev/framework/ministore/minishopopencomponent2/API/audit/audit_brand.html', '', $item[ 'reject_reason' ]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步商品类目
|
||||
*/
|
||||
public function syncCategory($site_id)
|
||||
{
|
||||
$res = ( new Weapp($site_id) )->getCatList();
|
||||
if ($res[ 'code' ] < 0) return $res;
|
||||
|
||||
if (!empty($res[ 'data' ])) {
|
||||
model('shopcompoent_category')->delete([ [ 'create_time', '<', time() ] ]);
|
||||
$data = [];
|
||||
foreach ($res[ 'data' ] as $item) {
|
||||
$data[] = [
|
||||
'first_cat_id' => $item['first_cat_id'],
|
||||
'second_cat_id' => $item['second_cat_id'],
|
||||
'third_cat_id' => $item['third_cat_id'],
|
||||
'first_cat_name' => $item['first_cat_name'],
|
||||
'second_cat_name' => $item['second_cat_name'],
|
||||
'third_cat_name' => $item['third_cat_name'],
|
||||
'qualification' => $item['qualification'],
|
||||
'qualification_type' => $item['qualification_type'],
|
||||
'product_qualification_type' => $item['product_qualification_type'],
|
||||
'product_qualification' => $item['product_qualification'],
|
||||
'create_time' => time(),
|
||||
];
|
||||
}
|
||||
model('shopcompoent_category')->addList($data);
|
||||
Cache::tag('wxCategory')->clear();
|
||||
return $this->success(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传类目资质
|
||||
*/
|
||||
public function uploadQualifications($param, $site_id)
|
||||
{
|
||||
$category = model('shopcompoent_category')->getInfo([ [ 'third_cat_id', '=', $param[ 'third_cat_id' ] ] ]);
|
||||
|
||||
$img1 = '';
|
||||
if (!empty($param[ 'leimu_qualification' ])) {
|
||||
$img_info1 = ( new Weapp($site_id) )->getImg(img($param[ 'leimu_qualification' ]));
|
||||
if ($img_info1[ 'code' ] == 0) {
|
||||
$img1 = $img_info1[ 'data' ][ 'img_info' ][ 'temp_img_url' ];
|
||||
}
|
||||
}
|
||||
|
||||
$img2 = '';
|
||||
if (!empty($param[ 'product_qualification' ])) {
|
||||
$img_info2 = ( new Weapp($site_id) )->getImg(img($param[ 'product_qualification' ]));
|
||||
if ($img_info2[ 'code' ] == 0) {
|
||||
$img2 = $img_info2[ 'data' ][ 'img_info' ][ 'temp_img_url' ];
|
||||
}
|
||||
}
|
||||
|
||||
if ($category[ 'qualification_type' ] != 0) {
|
||||
$zhengshu = '';
|
||||
if (isset($param[ 'zhengshu' ])) {
|
||||
$zhengshu_info = ( new Weapp($site_id) )->getImg(img($param[ 'zhengshu' ]));
|
||||
if ($zhengshu_info[ 'code' ] == 0) {
|
||||
$zhengshu = $zhengshu_info[ 'data' ][ 'img_info' ][ 'temp_img_url' ];
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'license' => $zhengshu ?? '',
|
||||
'category_info' => [
|
||||
'level1' => $param[ 'first_cat_id' ],
|
||||
'level2' => $param[ 'second_cat_id' ],
|
||||
'level3' => $param[ 'third_cat_id' ],
|
||||
'certificate' => []
|
||||
]
|
||||
];
|
||||
if (isset($param[ 'leimu_qualification' ])) {
|
||||
$data['category_info']['certificate'][] = $img1;
|
||||
}
|
||||
if (isset($param[ 'product_qualification' ])) {
|
||||
$data['category_info']['certificate'][] = $img2;
|
||||
}
|
||||
|
||||
$res = ( new Weapp($site_id) )->auditCategory($data);
|
||||
if ($res[ 'code' ] < 0 && $res[ 'data' ] != '1050003') return $res;
|
||||
} else {
|
||||
$res = $this->success();
|
||||
}
|
||||
|
||||
$audit_data = [
|
||||
'site_id' => $site_id,
|
||||
'third_cat_id' => $param[ 'third_cat_id' ],
|
||||
'audit_id' => $res[ 'data' ],
|
||||
'audit_time' => time(),
|
||||
'certificate' => $img1,
|
||||
'qualification_pics' => $img2,
|
||||
'status' => 0
|
||||
];
|
||||
if ($category[ 'qualification_type' ] == 0 || $res[ 'data' ] == '1050003') {
|
||||
$audit_data[ 'status' ] = 1;
|
||||
$audit_data[ 'audit_time' ] = time();
|
||||
}
|
||||
Cache::set('license_' . $param[ 'third_cat_id' ], img($param[ 'zhengshu' ]));
|
||||
|
||||
$is_exit = model('shopcompoent_category_audit')->getCount([ [ 'site_id', '=', $site_id ], [ 'third_cat_id', '=', $param[ 'third_cat_id' ] ] ]);
|
||||
if ($is_exit) {
|
||||
model('shopcompoent_category_audit')->update($audit_data, [ [ 'site_id', '=', $site_id ], [ 'third_cat_id', '=', $param[ 'third_cat_id' ] ] ]);
|
||||
} else {
|
||||
model('shopcompoent_category_audit')->add($audit_data);
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类目通过上级类目ID
|
||||
* @param $level
|
||||
* @param int $pid
|
||||
* @return array
|
||||
*/
|
||||
public function getCategoryByParent($level, $pid = 0)
|
||||
{
|
||||
$cache = Cache::get("wxCategory_{$level}_{$pid}");
|
||||
if ($cache) return $cache;
|
||||
|
||||
switch ( $level ) {
|
||||
case 1:
|
||||
$list = model('shopcompoent_category')->getList([], '*', '', '', null, 'first_cat_id');
|
||||
break;
|
||||
case 2:
|
||||
$list = model('shopcompoent_category')->getList([ [ 'first_cat_id', '=', $pid ] ], '*', '', '', null, 'second_cat_id');
|
||||
break;
|
||||
case 3:
|
||||
$list = model('shopcompoent_category')->getList([ [ 'second_cat_id', '=', $pid ] ], '*', '', '', null, 'third_cat_name');
|
||||
break;
|
||||
}
|
||||
|
||||
$data = $this->success($list);
|
||||
Cache::tag('wxCategory')->set("wxCategory_{$level}_{$pid}", $data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分类是否需要上传资质
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function isQualifications($param)
|
||||
{
|
||||
$info = model('shopcompoent_category')->getInfo([ [ 'third_cat_id', '=', $param[ 'third_cat_id' ] ] ], 'qualification_type,product_qualification_type');
|
||||
if ($info[ 'qualification_type' ] != 0 || $info[ 'product_qualification_type' ] != 0) {
|
||||
$audit_info = model('shopcompoent_category_audit')->getInfo([ [ 'status', '=', 1 ], [ 'site_id', '=', $param[ 'site_id' ] ], [ 'third_cat_id', '=', $param[ 'third_cat_id' ] ] ]);
|
||||
if (empty($audit_info)) return $this->error();
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类信息
|
||||
* @param $third_cat_id
|
||||
* @param $site_id
|
||||
*/
|
||||
public function getCategoryInfo($third_cat_id, $site_id)
|
||||
{
|
||||
$info = model('shopcompoent_category')->getInfo([ [ 'third_cat_id', '=', $third_cat_id ] ]);
|
||||
if (empty($info)) return $info;
|
||||
|
||||
$audit_info = model('shopcompoent_category_audit')->getInfo([ [ 'site_id', '=', $site_id ], [ 'third_cat_id', '=', $third_cat_id ] ]);
|
||||
if (empty($audit_info)) {
|
||||
$audit_info = [
|
||||
'certificate' => '',
|
||||
'qualification_pics' => '',
|
||||
'audit_id' => '',
|
||||
'audit_time' => 0,
|
||||
'status' => 0,
|
||||
'reject_reason' => ''
|
||||
];
|
||||
if (( $info[ 'qualification_type' ] == 0 && $info[ 'product_qualification_type' ] == 0 ) || ( $info[ 'qualification_type' ] == 2 && $info[ 'product_qualification_type' ] == 2 )) $audit_info[ 'status' ] = 1;
|
||||
}
|
||||
|
||||
return array_merge($info, $audit_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步类目审核状态
|
||||
* @param $site_id
|
||||
*/
|
||||
public function syncCategoryAuditStatus($site_id)
|
||||
{
|
||||
$audit_list = model('shopcompoent_category_audit')->getList([ [ 'site_id', '=', $site_id ], [ 'audit_id', '<>', '' ], [ 'status', '=', 0 ] ]);
|
||||
if (!empty($audit_list)) {
|
||||
$weapp = new Weapp($site_id);
|
||||
foreach ($audit_list as $item) {
|
||||
$audit_result = $weapp->getAuditResult($item[ 'audit_id' ]);
|
||||
if ($audit_result[ 'code' ] == 0) {
|
||||
model('shopcompoent_category_audit')->update([ 'status' => $audit_result[ 'data' ][ 'status' ], 'audit_time' => time(), 'reject_reason' => $audit_result[ 'data' ][ 'reject_reason' ] ], [ [ 'id', '=', $item[ 'id' ] ] ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
428
addon/shopcomponent/model/Goods.php
Executable file
428
addon/shopcomponent/model/Goods.php
Executable file
@@ -0,0 +1,428 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\shopcomponent\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
|
||||
class Goods extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 商品状态
|
||||
* @var string[]
|
||||
*/
|
||||
private $status = [
|
||||
0 => '未上架',
|
||||
5 => '上架中',
|
||||
11 => '已下架',
|
||||
13 => '违规下架'
|
||||
];
|
||||
|
||||
/**
|
||||
* 审核状态
|
||||
* @var string[]
|
||||
*/
|
||||
private $editStatus = [
|
||||
0 => '审核中',
|
||||
1 => '编辑中',
|
||||
2 => '审核中',
|
||||
3 => '审核失败',
|
||||
4 => '审核成功',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取商品列表
|
||||
* @param array $condition
|
||||
* @param bool $field
|
||||
* @param string $order
|
||||
* @param int $page
|
||||
* @param int $list_rows
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @return array
|
||||
*/
|
||||
public function getGoodsPageList($condition = [], $field = true, $order = '', $page = 1, $list_rows = PAGE_LIST_ROWS, $alias = 'a', $join = [])
|
||||
{
|
||||
$field = 'sg.*,
|
||||
g.goods_name,g.goods_image,g.price,g.goods_stock,g.recommend_way';
|
||||
$alias = 'sg';
|
||||
$join = [
|
||||
[ 'goods g', 'g.goods_id = sg.out_product_id', 'inner' ],
|
||||
];
|
||||
$data = model('shopcompoent_goods')->pageList($condition, $field, $order, $page, $list_rows, $alias, $join);
|
||||
|
||||
if (!empty($data[ 'list' ])) {
|
||||
foreach ($data[ 'list' ] as $k => $item) {
|
||||
$data[ 'list' ][ $k ][ 'goods_stock' ] = numberFormat($data[ 'list' ][ $k ][ 'goods_stock' ]);
|
||||
$data[ 'list' ][ $k ][ 'status_name' ] = $this->status[ $item[ 'status' ] ] ?? '';
|
||||
$data[ 'list' ][ $k ][ 'edit_status_name' ] = $this->editStatus[ $item[ 'edit_status' ] ] ?? '';
|
||||
$arr_img = explode(',', $item[ 'goods_image' ]);
|
||||
$data[ 'list' ][ $k ][ 'cover_img' ] = $arr_img[ 0 ] ?? '';
|
||||
$data[ 'list' ][ $k ][ 'create_time' ] = $item[ 'create_time' ] > 0 ? time_to_date($item[ 'create_time' ]) : '--';
|
||||
$data[ 'list' ][ $k ][ 'audit_time' ] = $item[ 'audit_time' ] > 0 ? time_to_date($item[ 'audit_time' ]) : '--';
|
||||
$data[ 'list' ][ $k ][ 'reject_reason' ] = str_replace('https://developers.weixin.qq.com/miniprogram/dev/framework/ministore/minishopopencomponent/API/spu/add_spu.html', '', $item[ 'reject_reason' ]);
|
||||
}
|
||||
}
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步商品库商品
|
||||
*/
|
||||
public function syncGoods($start, $limit, $site_id, $status = 5)
|
||||
{
|
||||
$weapp = new Weapp($site_id);
|
||||
$sync_res = $weapp->getSpuPage([ 'page' => $start, 'page_size' => $limit, 'status' => $status ]);
|
||||
|
||||
if ($sync_res[ 'code' ] < 0) return $sync_res;
|
||||
|
||||
if (!empty($sync_res[ 'data' ][ 'list' ])) {
|
||||
foreach ($sync_res[ 'data' ][ 'list' ] as $goods_item) {
|
||||
$count = model('shopcompoent_goods')->getCount([ [ 'out_product_id', '=', $goods_item[ 'out_product_id' ] ], [ 'site_id', '=', $site_id ] ]);
|
||||
if ($count) {
|
||||
model('shopcompoent_goods')->update([
|
||||
'status' => $goods_item[ 'status' ],
|
||||
'edit_status' => $goods_item[ 'edit_status' ],
|
||||
'audit_time' => empty($goods_item[ 'audit_info' ]) ? 0 : strtotime($goods_item[ 'audit_info' ][ 'audit_time' ]),
|
||||
'reject_reason' => $goods_item[ 'edit_status' ] == 3 ? $goods_item[ 'audit_info' ][ 'reject_reason' ] : ''
|
||||
], [
|
||||
[ 'out_product_id', '=', $goods_item[ 'out_product_id' ] ]
|
||||
]);
|
||||
} else {
|
||||
$category = ( new Category() )->getCategoryInfo($goods_item[ 'third_cat_id' ], $site_id);
|
||||
model('shopcompoent_goods')->add([
|
||||
'site_id' => $site_id,
|
||||
'product_id' => $goods_item[ 'product_id' ],
|
||||
'out_product_id' => $goods_item[ 'out_product_id' ],
|
||||
'third_cat_id' => $goods_item[ 'third_cat_id' ],
|
||||
'brand_id' => $goods_item[ 'brand_id' ],
|
||||
'info_version' => $goods_item[ 'info_version' ],
|
||||
'status' => $goods_item[ 'status' ],
|
||||
'edit_status' => $goods_item[ 'edit_status' ],
|
||||
'create_time' => strtotime($goods_item[ 'create_time' ]),
|
||||
'update_time' => strtotime($goods_item[ 'update_time' ]),
|
||||
'audit_time' => empty($goods_item[ 'audit_info' ]) ? 0 : strtotime($goods_item[ 'audit_info' ][ 'audit_time' ]),
|
||||
'reject_reason' => $goods_item[ 'edit_status' ] == 3 ? $goods_item[ 'audit_info' ][ 'reject_reason' ] : '',
|
||||
'cat_name' => "{$category['first_cat_name']}>{$category['second_cat_name']}>{$category['third_cat_name']}"
|
||||
]);
|
||||
}
|
||||
}
|
||||
$total_page = ceil($sync_res[ 'data' ][ 'total' ] / $limit);
|
||||
return $this->success([ 'page' => $start, 'total_page' => $total_page ]);
|
||||
} else {
|
||||
return $this->success([ 'page' => $start, 'total_page' => 1 ]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商品
|
||||
* @param $param
|
||||
*/
|
||||
public function addGoods($param)
|
||||
{
|
||||
$goods_list = model('goods')->getList([ [ 'goods_id', 'in', explode(',', $param[ 'goods_ids' ]) ], [ 'site_id', '=', $param[ 'site_id' ] ] ], 'goods_id,goods_name,goods_image,sku_id,goods_content');
|
||||
if (!empty($goods_list)) {
|
||||
$category = ( new Category() )->getCategoryInfo($param[ 'third_cat_id' ], $param[ 'site_id' ]);
|
||||
if (empty($category) || $category[ 'status' ] == 0) return $this->error('', '该类目不存在或未审核通过');
|
||||
|
||||
$weapp = new Weapp($param[ 'site_id' ]);
|
||||
foreach ($goods_list as $goods_item) {
|
||||
// 需加到库中的商品数据
|
||||
$goods_data = [
|
||||
'out_product_id' => $goods_item[ 'goods_id' ],
|
||||
'third_cat_id' => $param[ 'third_cat_id' ],
|
||||
'brand_id' => $param[ 'brand_id' ] ?? 2100000000,
|
||||
'info_version' => '0.0.1',
|
||||
];
|
||||
|
||||
//处理图片
|
||||
$goods_image_arr = $this->handleImg($goods_item[ 'goods_image' ]);
|
||||
$goods_image = [];
|
||||
foreach ($goods_image_arr as $img_k => $img_y) {
|
||||
$res = $weapp->getImg($img_y);
|
||||
if ($res[ 'code' ] == 0) {
|
||||
$goods_image[] = $res[ 'data' ][ 'img_info' ][ 'temp_img_url' ];
|
||||
}
|
||||
}
|
||||
|
||||
// 同步商品所需数据
|
||||
$spu_data = [
|
||||
'title' => $goods_item[ 'goods_name' ],
|
||||
'path' => 'pages/goods/detail?sku_id=' . $goods_item[ 'sku_id' ],
|
||||
'head_img' => $goods_image,
|
||||
'qualification_pics' => $category[ 'product_qualification_type' ] == 0 ? '' : explode(',', $category[ 'qualification_pics' ]),
|
||||
'desc_info' => [
|
||||
'desc' => $goods_item[ 'goods_content' ]
|
||||
],
|
||||
'skus' => []
|
||||
];
|
||||
|
||||
$sku_list = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_item[ 'goods_id' ] ] ], 'sku_id,sku_no,sku_image,discount_price,market_price,stock,sku_spec_format');
|
||||
foreach ($sku_list as $sku_item) {
|
||||
//图片处理
|
||||
$sku_res = $weapp->getImg($this->handleImg($sku_item[ 'sku_image' ])[ 0 ]);
|
||||
$sku_image = '';
|
||||
if ($sku_res[ 'code' ] == 0) {
|
||||
$sku_image = $sku_res[ 'data' ][ 'img_info' ][ 'temp_img_url' ];
|
||||
}
|
||||
|
||||
$sku_data = [
|
||||
'out_product_id' => $goods_item[ 'goods_id' ],
|
||||
'out_sku_id' => $sku_item[ 'sku_id' ],
|
||||
'thumb_img' => $sku_image,
|
||||
'sale_price' => $sku_item[ 'discount_price' ] * 100,
|
||||
'market_price' => $sku_item[ 'market_price' ] * 100,
|
||||
'stock_num' => numberFormat($sku_item[ 'stock' ]),
|
||||
'sku_code' => $sku_item[ 'sku_no' ],
|
||||
'sku_attrs' => []
|
||||
];
|
||||
if (!empty($sku_item[ 'sku_spec_format' ])) {
|
||||
foreach (json_decode($sku_item[ 'sku_spec_format' ], true) as $spec_item) {
|
||||
$sku_data['sku_attrs'][] = [
|
||||
'attr_key' => $spec_item['spec_name'],
|
||||
'attr_value' => $spec_item['spec_value_name']
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$sku_data[ 'sku_attrs' ] = [
|
||||
[
|
||||
'attr_key' => '',
|
||||
'attr_value' => ''
|
||||
]
|
||||
];
|
||||
}
|
||||
$spu_data['skus'][] = $sku_data;
|
||||
}
|
||||
|
||||
// 添加商品到小程序
|
||||
$add_res = $weapp->addSpu(array_merge($goods_data, $spu_data));
|
||||
if ($add_res[ 'code' ] != 0) return $add_res;
|
||||
|
||||
$goods_data[ 'product_id' ] = $add_res[ 'data' ][ 'product_id' ];
|
||||
$goods_data[ 'create_time' ] = !empty($add_res[ 'data' ][ 'create_time' ]) ? strtotime($add_res[ 'data' ][ 'create_time' ]) : time();
|
||||
$goods_data[ 'site_id' ] = $param[ 'site_id' ];
|
||||
$goods_data[ 'cat_name' ] = "{$category['first_cat_name']}>{$category['second_cat_name']}>{$category['third_cat_name']}";
|
||||
|
||||
model('shopcompoent_goods')->add($goods_data);
|
||||
}
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', '未获取到要添加的商品');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function updateGoods($param)
|
||||
{
|
||||
$shopcompoent_goods_info = model('shopcompoent_goods')->getInfo([ [ 'out_product_id', '=', $param[ 'goods_id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ], '*');
|
||||
$goods_info = model('goods')->getInfo([ [ 'goods_id', '=', $param[ 'goods_id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ], 'goods_id,goods_name,goods_image,sku_id,goods_content');
|
||||
if (!empty($shopcompoent_goods_info) && !empty($goods_info)) {
|
||||
|
||||
$third_cat_id = $param[ 'third_cat_id' ] ?? $shopcompoent_goods_info[ 'third_cat_id' ];
|
||||
$category = ( new Category() )->getCategoryInfo($third_cat_id, $param[ 'site_id' ]);
|
||||
if (empty($category) || $category[ 'status' ] == 0) return $this->error('', '该类目不存在或未审核通过');
|
||||
|
||||
$weapp = new Weapp($param[ 'site_id' ]);
|
||||
|
||||
//处理图片
|
||||
$goods_image_arr = $this->handleImg($goods_info[ 'goods_image' ]);
|
||||
$goods_image = [];
|
||||
foreach ($goods_image_arr as $img_k => $img_y) {
|
||||
$res = $weapp->getImg($img_y);
|
||||
if ($res[ 'code' ] == 0) {
|
||||
$goods_image[] = $res[ 'data' ][ 'img_info' ][ 'temp_img_url' ];
|
||||
}
|
||||
}
|
||||
|
||||
// 同步商品所需数据
|
||||
$spu_data = [
|
||||
'out_product_id' => $goods_info[ 'goods_id' ],
|
||||
'third_cat_id' => $third_cat_id,
|
||||
'brand_id' => $param[ 'brand_id' ] ?? $shopcompoent_goods_info[ 'brand_id' ],
|
||||
'info_version' => '0.0.1',
|
||||
'title' => $goods_info[ 'goods_name' ],
|
||||
'path' => 'pages/goods/detail?sku_id=' . $goods_info[ 'sku_id' ],
|
||||
'head_img' => $goods_image,
|
||||
'qualification_pics' => $category[ 'product_qualification_type' ] == 0 ? '' : explode(',', $category[ 'qualification_pics' ]),
|
||||
'desc_info' => [
|
||||
'desc' => $goods_info[ 'goods_content' ]
|
||||
],
|
||||
'skus' => []
|
||||
];
|
||||
|
||||
$sku_list = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_info[ 'goods_id' ] ] ], 'sku_id,sku_no,sku_image,discount_price,market_price,stock,sku_spec_format');
|
||||
foreach ($sku_list as $sku_item) {
|
||||
//图片处理
|
||||
$sku_res = $weapp->getImg($this->handleImg($sku_item[ 'sku_image' ])[ 0 ]);
|
||||
$sku_image = '';
|
||||
if ($sku_res[ 'code' ] == 0) {
|
||||
$sku_image = $sku_res[ 'data' ][ 'img_info' ][ 'temp_img_url' ];
|
||||
}
|
||||
|
||||
$sku_data = [
|
||||
'out_product_id' => $goods_info[ 'goods_id' ],
|
||||
'out_sku_id' => $sku_item[ 'sku_id' ],
|
||||
'thumb_img' => $sku_image,
|
||||
'sale_price' => $sku_item[ 'discount_price' ] * 100,
|
||||
'market_price' => $sku_item[ 'market_price' ] * 100,
|
||||
'stock_num' => numberFormat($sku_item[ 'stock' ]),
|
||||
'sku_code' => $sku_item[ 'sku_no' ],
|
||||
'sku_attrs' => []
|
||||
];
|
||||
if (!empty($sku_item[ 'sku_spec_format' ])) {
|
||||
foreach (json_decode($sku_item[ 'sku_spec_format' ], true) as $spec_item) {
|
||||
$sku_data['sku_attrs'][] = [
|
||||
'attr_key' => $spec_item['spec_name'],
|
||||
'attr_value' => $spec_item['spec_value_name']
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$sku_data[ 'sku_attrs' ] = [
|
||||
[
|
||||
'attr_key' => '',
|
||||
'attr_value' => ''
|
||||
]
|
||||
];
|
||||
}
|
||||
$spu_data['skus'][] = $sku_data;
|
||||
}
|
||||
|
||||
// 更新商品
|
||||
$update_res = $weapp->updateSpu($spu_data);
|
||||
if ($update_res[ 'code' ] != 0) return $update_res;
|
||||
|
||||
$goods_data = [
|
||||
'edit_status' => 0,
|
||||
'update_time' => time(),
|
||||
'third_cat_id' => $third_cat_id,
|
||||
'cat_name' => "{$category['first_cat_name']}>{$category['second_cat_name']}>{$category['third_cat_name']}"
|
||||
];
|
||||
|
||||
model('shopcompoent_goods')->update($goods_data, [ [ 'out_product_id', '=', $param[ 'goods_id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ]);
|
||||
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', '未获取到要更新的商品');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理图片
|
||||
* @param $images
|
||||
* @return false|string[]
|
||||
*/
|
||||
private function handleImg($images)
|
||||
{
|
||||
$img_arr = explode(',', $images);
|
||||
foreach ($img_arr as $k => $v) {
|
||||
$img_arr[ $k ] = img($v);
|
||||
}
|
||||
return $img_arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
* @param $id
|
||||
* @param $site_id
|
||||
*/
|
||||
public function deleteGoods($goods_ids, $site_id)
|
||||
{
|
||||
if (!empty($goods_ids)) {
|
||||
$array_goodsIds = explode(',', $goods_ids);
|
||||
}
|
||||
foreach ($array_goodsIds as $k => $goods_id) {
|
||||
$res[ $k ] = ( new Weapp($site_id) )->delSpu([ 'out_product_id' => $goods_id ]);
|
||||
if ($res[ $k ][ 'code' ] != 0) return $res[ $k ];
|
||||
}
|
||||
model('shopcompoent_goods')->delete([ [ 'site_id', '=', $site_id ], [ 'out_product_id', 'in', $goods_ids ] ]);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品上架
|
||||
* @param $goods_ids
|
||||
* @param $site_id
|
||||
* @return array|mixed
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function goodsListing($goods_ids, $site_id)
|
||||
{
|
||||
if (!empty($goods_ids)) {
|
||||
$array_goodsIds = explode(',', $goods_ids);
|
||||
}
|
||||
foreach ($array_goodsIds as $k => $goods_id) {
|
||||
$res[ $k ] = ( new Weapp($site_id) )->listing([ 'out_product_id' => $goods_id ]);
|
||||
if ($res[ $k ][ 'code' ] != 0) return $res[ $k ];
|
||||
}
|
||||
model('shopcompoent_goods')->update([ 'status' => 5 ], [ [ 'site_id', '=', $site_id ], [ 'out_product_id', 'in', $goods_ids ] ]);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品下架
|
||||
* @param $goods_ids
|
||||
* @param $site_id
|
||||
* @return array|mixed
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function goodsDelisting($goods_ids, $site_id)
|
||||
{
|
||||
if (!empty($goods_ids)) {
|
||||
$array_goodsIds = explode(',', $goods_ids);
|
||||
}
|
||||
foreach ($array_goodsIds as $k => $goods_id) {
|
||||
$res[ $k ] = ( new Weapp($site_id) )->delisting([ 'out_product_id' => $goods_id ]);
|
||||
if ($res[ $k ][ 'code' ] != 0) return $res[ $k ];
|
||||
}
|
||||
model('shopcompoent_goods')->update([ 'status' => 11 ], [ [ 'site_id', '=', $site_id ], [ 'out_product_id', 'in', $goods_ids ] ]);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $site_id
|
||||
*/
|
||||
public function getOrderPayInfo($site_id)
|
||||
{
|
||||
$join = [
|
||||
[ 'goods g', 'g.goods_id = sg.out_product_id', 'left' ]
|
||||
];
|
||||
$condition = [
|
||||
[ 'sg.site_id', '=', $site_id ],
|
||||
[ 'sg.status', '=', 5 ],
|
||||
[ 'sg.edit_status', '=', 4 ],
|
||||
[ 'g.is_delete', '=', 0 ],
|
||||
[ 'g.goods_state', '=', 1 ]
|
||||
];
|
||||
$goods_info = model('shopcompoent_goods')->getInfo($condition, 'g.goods_name,g.price,g.goods_id,g.sku_id', 'sg', $join);
|
||||
if (empty($goods_info)) return $this->error('', '请先将商品同步到微信侧,等待商品审核通过并已上架');
|
||||
|
||||
$qrcode_res = event('Qrcode', [
|
||||
'site_id' => $site_id,
|
||||
'app_type' => 'weapp',
|
||||
'type' => 'create',
|
||||
'data' => [
|
||||
'goods_id' => $goods_info[ 'goods_id' ],
|
||||
'is_test' => 1
|
||||
],
|
||||
'page' => '/pages/goods/detail',
|
||||
'qrcode_path' => 'upload/qrcode/goods',
|
||||
'qrcode_name' => 'goods_qrcode_' . $goods_info[ 'sku_id' ]
|
||||
], true);
|
||||
if ($qrcode_res[ 'code' ] != 0) return $qrcode_res;
|
||||
|
||||
$goods_info[ 'qrcode_path' ] = $qrcode_res[ 'data' ][ 'path' ];
|
||||
|
||||
return $this->success($goods_info);
|
||||
}
|
||||
}
|
||||
173
addon/shopcomponent/model/Order.php
Executable file
173
addon/shopcomponent/model/Order.php
Executable file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\shopcomponent\model;
|
||||
|
||||
use app\dict\order_refund\OrderRefundDict;
|
||||
use app\model\BaseModel;
|
||||
use app\model\order\OrderRefund;
|
||||
|
||||
class Order extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 订单发货之后
|
||||
*/
|
||||
public function delivery($order_id)
|
||||
{
|
||||
$order = model('order')->getInfo([ [ 'order_id', '=', $order_id ] ], 'site_id,is_video_number,pay_type,member_id,order_type');
|
||||
if ($order[ 'is_video_number' ] && $order[ 'pay_type' ] == 'wechatpay') {
|
||||
$member = model('member')->getInfo([ [ 'member_id', '=', $order[ 'member_id' ] ] ], 'weapp_openid');
|
||||
$weapp = new Weapp($order[ 'site_id' ]);
|
||||
$data = [
|
||||
'out_order_id' => $order_id,
|
||||
'openid' => $member[ 'weapp_openid' ],
|
||||
'finish_all_delivery' => 1,
|
||||
'delivery_list' => []
|
||||
];
|
||||
if ($order[ 'order_type' ] == 1) {
|
||||
$package_list = model('express_delivery_package')->getList([ [ 'order_id', '=', $order_id ] ], 'express_company_name,delivery_no,order_goods_id_array');
|
||||
if (!empty($package_list)) {
|
||||
$company_list = $weapp->getCompanyList();
|
||||
foreach ($package_list as $item) {
|
||||
$delivery_id = 'OTHERS';
|
||||
if ($company_list[ 'code' ] == 0) {
|
||||
$index = array_search($item[ 'express_company_name' ], array_column($company_list[ 'data' ], 'delivery_name'));
|
||||
if ($index !== false && isset($company_list[ 'data' ][ $index ])) {
|
||||
$delivery_id = $company_list[ 'data' ][ $index ][ 'delivery_id' ];
|
||||
}
|
||||
}
|
||||
|
||||
$order_goods_model = model('order_goods')->getList([ [ 'order_goods_id', "in", $item[ 'order_goods_id_array' ] ] ], "goods_id,sku_id,num");
|
||||
$goods_id_arr = [];
|
||||
$sku_id_arr = [];
|
||||
$number = 0;
|
||||
foreach ($order_goods_model as $order_iem) {
|
||||
$goods_id_arr[] = $order_iem[ 'goods_id' ];
|
||||
$sku_id_arr[] = $order_iem[ 'sku_id' ];
|
||||
$number += $order_iem[ 'num' ];
|
||||
}
|
||||
|
||||
$data['delivery_list'][] = [
|
||||
'delivery_id' => $delivery_id,
|
||||
'waybill_id' => $item['delivery_no'],
|
||||
'product_info_list' => [
|
||||
[
|
||||
'out_product_id' => implode(',', $goods_id_arr),
|
||||
'out_sku_id' => implode(',', $sku_id_arr),
|
||||
'product_cnt' => $number
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$res = $weapp->sendDelivery($data);
|
||||
return $res;
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单收货
|
||||
* @param $order_id
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function takeDelivery($order_id)
|
||||
{
|
||||
$order = model('order')->getInfo([ [ 'order_id', '=', $order_id ] ], 'site_id,is_video_number,pay_type,member_id,order_type');
|
||||
if ($order[ 'is_video_number' ] && $order[ 'pay_type' ] == 'wechatpay') {
|
||||
$member = model('member')->getInfo([ [ 'member_id', '=', $order[ 'member_id' ] ] ], 'weapp_openid');
|
||||
$weapp = new Weapp($order[ 'site_id' ]);
|
||||
$res = $weapp->recieveDelivery([ 'out_order_id' => $order_id, 'openid' => $member[ 'weapp_openid' ] ]);
|
||||
if ($res[ 'code' ] < 0) {
|
||||
return $this->error('', $res[ 'message' ]);
|
||||
}
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起退款申请
|
||||
* @param $param
|
||||
*/
|
||||
public function refundApply($param)
|
||||
{
|
||||
$join = [
|
||||
[ 'order o', 'o.order_id = og.order_id', 'left' ]
|
||||
];
|
||||
$info = model('order_goods')->getInfo([ [ 'og.order_goods_id', '=', $param[ 'order_goods_id' ] ] ], 'og.out_aftersale_id,og.order_goods_id,og.goods_id,og.sku_id,og.num,o.order_id,o.site_id,o.is_video_number,o.pay_type,o.member_id', 'og', $join);
|
||||
|
||||
if ($info[ 'is_video_number' ] && $info[ 'pay_type' ] == 'wechatpay') {
|
||||
$member = model('member')->getInfo([ [ 'member_id', '=', $info[ 'member_id' ] ] ], 'weapp_openid');
|
||||
$data = [
|
||||
'out_order_id' => (string) $info[ 'order_id' ],
|
||||
'out_aftersale_id' => $info[ 'out_aftersale_id' ],
|
||||
'openid' => $member[ 'weapp_openid' ],
|
||||
'type' => (int) $param[ 'refund_type' ],
|
||||
'product_info' => [
|
||||
'out_product_id' => (string) $info[ 'goods_id' ],
|
||||
'out_sku_id' => (string) $info[ 'sku_id' ],
|
||||
'product_cnt' => (int) $info[ 'num' ],
|
||||
],
|
||||
'refund_reason' => !empty($param[ 'refund_remark' ]) ? $param[ 'refund_remark' ] : "无",
|
||||
'refund_reason_type' => 12,
|
||||
'orderamt' => round($param[ 'refund_apply_money' ] * 100)
|
||||
];
|
||||
$weapp = new Weapp($info[ 'site_id' ]);
|
||||
$weapp->addAftersale($data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 维权状态变更
|
||||
*/
|
||||
public function refundStatusChange($param)
|
||||
{
|
||||
if ($param[ 'refund_status' ] != OrderRefundDict::REFUND_APPLY) {
|
||||
$join = [
|
||||
[ 'order o', 'o.order_id = og.order_id', 'left' ]
|
||||
];
|
||||
$info = model('order_goods')->getInfo([ [ 'og.order_goods_id', '=', $param[ 'order_goods_id' ] ] ], 'og.order_goods_id,og.refund_type,o.order_id,o.site_id,o.is_video_number,o.pay_type,o.member_id', 'og', $join);
|
||||
|
||||
if ($info[ 'is_video_number' ] && $info[ 'pay_type' ] == 'wechatpay') {
|
||||
$data = [
|
||||
'out_order_id' => $info[ 'order_id' ],
|
||||
'out_aftersale_id' => $info[ 'order_goods_id' ],
|
||||
'finish_all_aftersale' => 0
|
||||
];
|
||||
|
||||
// status 0:未受理,1:用户取消,2:商家受理中,3:商家逾期未处理,4:商家拒绝退款,5:商家拒绝退货退款,6:待买家退货,7:退货退款关闭,8:待商家收货,11:商家退款中,12:商家逾期未退款,13:退款完成,14:退货退款完成
|
||||
switch ( $param[ 'refund_status' ] ) {
|
||||
case 0: // 会员取消或商家关闭
|
||||
$data[ 'status' ] = $param[ 'action_way' ] == 1 ? 1 : 0;
|
||||
break;
|
||||
case OrderRefundDict::REFUND_CONFIRM: // 同意退款
|
||||
$data[ 'status' ] = 2;
|
||||
break;
|
||||
case OrderRefundDict::REFUND_DIEAGREE: // 拒绝退款
|
||||
$data[ 'status' ] = $info[ 'refund_type' ] == 1 ? 4 : 5;
|
||||
break;
|
||||
case OrderRefundDict::REFUND_COMPLETE: // 退款完成
|
||||
$data[ 'status' ] = $info[ 'refund_type' ] == 1 ? 13 : 14;
|
||||
$order_goods_count = model('order_goods')->getCount([ [ "order_id", "=", $info[ 'order_id' ] ] ], "order_goods_id");
|
||||
$refund_count = model('order_goods')->getCount([ [ "order_id", "=", $info[ 'order_id' ] ], [ "refund_status", "=", OrderRefundDict::REFUND_COMPLETE ] ], "order_goods_id");
|
||||
if ($order_goods_count == $refund_count) $data[ 'finish_all_aftersale' ] = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// if (isset($data['status'])) {
|
||||
// $weapp = new Weapp($info['site_id']);
|
||||
// $weapp->updateAftersale($data);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
657
addon/shopcomponent/model/Weapp.php
Executable file
657
addon/shopcomponent/model/Weapp.php
Executable file
@@ -0,0 +1,657 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\shopcomponent\model;
|
||||
|
||||
use addon\weapp\model\Config as WeappConfigModel;
|
||||
use addon\wxoplatform\model\Config as WxOplatformConfigModel;
|
||||
use app\model\BaseModel;
|
||||
use EasyWeChat\Factory;
|
||||
use think\facade\Cache;
|
||||
|
||||
class Weapp extends BaseModel
|
||||
{
|
||||
public function __construct($site_id = 0)
|
||||
{
|
||||
//微信小程序配置
|
||||
$weapp_config_model = new WeappConfigModel();
|
||||
$weapp_config = $weapp_config_model->getWeappConfig($site_id)[ "data" ][ "value" ];
|
||||
|
||||
if (isset($weapp_config[ 'is_authopen' ]) && addon_is_exit('wxoplatform')) {
|
||||
$plateform_config_model = new WxOplatformConfigModel();
|
||||
$plateform_config = $plateform_config_model->getOplatformConfig();
|
||||
$plateform_config = $plateform_config[ "data" ][ "value" ];
|
||||
|
||||
$config = [
|
||||
'app_id' => $plateform_config[ "appid" ] ?? '',
|
||||
'secret' => $plateform_config[ "secret" ] ?? '',
|
||||
'token' => $plateform_config[ "token" ] ?? '',
|
||||
'aes_key' => $plateform_config[ "aes_key" ] ?? '',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
'permission' => 0777,
|
||||
'file' => 'runtime/log/wechat/oplatform.logs',
|
||||
],
|
||||
];
|
||||
$open_platform = Factory::openPlatform($config);
|
||||
$this->app = $open_platform->miniProgram($weapp_config[ 'authorizer_appid' ], $weapp_config[ 'authorizer_refresh_token' ]);
|
||||
} else {
|
||||
$config = [
|
||||
'app_id' => $weapp_config[ "appid" ] ?? '',
|
||||
'secret' => $weapp_config[ "appsecret" ] ?? '',
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
'permission' => 0777,
|
||||
'file' => 'runtime/log/wechat/easywechat.logs',
|
||||
],
|
||||
];
|
||||
$this->app = Factory::miniProgram($config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测自定义交易组件接入状态
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function checkRegister()
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->check();
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result[ 'data' ]);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 接入申请
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->apply();
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信类目
|
||||
* @return array
|
||||
*/
|
||||
|
||||
public function getCatList()
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->get();
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result[ 'third_cat_list' ]);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交类目资质
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function auditCategory($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->auditCategory($param);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result[ 'audit_id' ]);
|
||||
} else {
|
||||
return $this->error($result[ 'errcode' ] ?? '', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加商品
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function addSpu($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->addSpu($param);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result[ 'data' ]);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function updateSpu($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->updateSpu($param);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result[ 'data' ]);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function getSpuPage($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->getSpuList($param);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success([ 'total' => $result[ 'total_num' ], 'list' => $result[ 'spus' ] ]);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品上架
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function listing($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->listingSpu($param[ 'product_id' ] ?? '', $param[ 'out_product_id' ] ?? '');
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品下架
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function delisting($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->delistingSpu($param[ 'product_id' ] ?? '', $param[ 'out_product_id' ] ?? '');
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function delSpu($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->delSpu($param[ 'product_id' ] ?? '', $param[ 'out_product_id' ] ?? '');
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function addOrder($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->addOrder($param);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result[ 'data' ]);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
public function getOrder($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->getOrder($param[ 'order_id' ] ?? '', $param[ 'out_order_id' ] ?? '', $param[ 'openid' ]);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result[ 'order' ]);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单支付状态同步
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function pay($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->payOrder($param);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取快递公司列表
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function getCompanyList()
|
||||
{
|
||||
$cache = Cache::get('weixinCompanyList');
|
||||
if ($cache) return $cache;
|
||||
|
||||
try {
|
||||
$result = $this->app->mini_store->getDeliveryCompanyList();
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
$data = $this->success($result[ 'company_list' ]);
|
||||
Cache::set('weixinCompanyList', $data);
|
||||
return $data;
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单发货
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function sendDelivery($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->sendDelivery($param[ 'order_id' ] ?? '', $param[ 'out_order_id' ] ?? '', $param[ 'openid' ], $param[ 'finish_all_delivery' ], $param[ 'delivery_list' ]);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单收货
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function recieveDelivery($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->recieveDelivery($param[ 'order_id' ] ?? '', $param[ 'out_order_id' ] ?? '', $param[ 'openid' ]);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建售后
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function addAftersale($param)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->addAftersale($param);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取审核状态
|
||||
* @param $audit_id
|
||||
* @return array
|
||||
*/
|
||||
public function getAuditResult($audit_id)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->auditResult($audit_id);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result[ 'data' ]);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成接入任务
|
||||
* @param $item
|
||||
* @return array
|
||||
*/
|
||||
public function finishAccessInfo($item)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->finish_access_info($item);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success();
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片信息
|
||||
* @param $item
|
||||
* @return array
|
||||
*/
|
||||
public function getImg($url)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->uploadImg($url);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function updateShop($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->updateShop($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function updateOrderType($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->updateOrderType($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function createOrder($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->addOrder($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getPaymentParams($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->getPaymentParams($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
* @return array
|
||||
* 同意退款
|
||||
*/
|
||||
public function orderRefund($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->orderRefund($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
* @return array
|
||||
* 拒绝退款
|
||||
*/
|
||||
public function orderNoRefund($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->orderNoRefund($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
* @return array
|
||||
* 同意退货
|
||||
*/
|
||||
public function aceptreturn($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->aceptreturn($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
* @return array
|
||||
* 同意退货
|
||||
*/
|
||||
public function cancel($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->cancel($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 卖家发货
|
||||
*/
|
||||
public function uploadreturninfo($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->uploadreturninfo($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//获取售后详情
|
||||
public function getAftersale($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->getAftersale($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新售后
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function updateAftersale($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->updateAftersale($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params
|
||||
* @return array
|
||||
* 获取售后订单列表
|
||||
*/
|
||||
public function getOrderList($params)
|
||||
{
|
||||
try {
|
||||
$result = $this->app->mini_store->getOrderList($params);
|
||||
if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
|
||||
return $this->success($result);
|
||||
} else {
|
||||
return $this->error('', $result[ 'errmsg' ]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user