Merge pull request 'dev' (#15) from dev into master
Reviewed-on: http://git.excellentkk.cn/mkm/shop-php/pulls/15
This commit is contained in:
commit
322d43eea2
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@ public/protocol.html
|
||||
/runtime/*
|
||||
runtime/swoole.pid
|
||||
cert_crmeb copy.key
|
||||
dump.rdb
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
namespace app;
|
||||
|
||||
use crmeb\utils\DingTalk;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\db\exception\PDOException;
|
||||
@ -65,6 +66,9 @@ class ExceptionHandle extends Handle
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
$this->report($e);
|
||||
if ($e->getCode() != 0) {
|
||||
DingTalk::exception($e, $e->getMessage(), $request);
|
||||
}
|
||||
// 其他错误交给系统处理
|
||||
if ($e instanceof ValidateException)
|
||||
return app('json')->fail($e->getMessage());
|
||||
|
@ -17,6 +17,7 @@ use app\common\dao\BaseDao;
|
||||
use app\common\model\community\Community;
|
||||
use app\common\model\system\Relevance;
|
||||
use app\common\repositories\system\RelevanceRepository;
|
||||
use think\facade\Db;
|
||||
|
||||
class CommunityDao extends BaseDao
|
||||
{
|
||||
@ -30,7 +31,8 @@ class CommunityDao extends BaseDao
|
||||
{
|
||||
$query = Community::hasWhere('author', function($query) use ($where){
|
||||
$query->when(isset($where['username']) && $where['username'] !== '', function ($query) use($where) {
|
||||
$query->whereLike('real_name|phone|nickname',"%{$where['username']}%");
|
||||
$uid = Db::name('merchant')->where('mer_name', $where['username'])->value('uid', -1);
|
||||
$query->where('uid', $uid);
|
||||
});
|
||||
$query->where(true);
|
||||
});
|
||||
@ -38,6 +40,9 @@ class CommunityDao extends BaseDao
|
||||
->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use($where) {
|
||||
$query->whereLike('Community.title',"%{$where['keyword']}%");
|
||||
})
|
||||
->when(!empty($where['resale_type']), function ($query) use($where) {
|
||||
$query->where('Community.resale_type', $where['resale_type']);
|
||||
})
|
||||
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use($where) {
|
||||
$query->where('Community.uid',$where['uid']);
|
||||
})
|
||||
|
@ -16,6 +16,12 @@ namespace app\common\dao\store;
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\CityArea;
|
||||
use app\common\model\store\GeoProvince;
|
||||
use app\common\model\store\GeoCity;
|
||||
use app\common\model\store\GeoArea;
|
||||
use app\common\model\store\GeoStreet;
|
||||
use app\common\model\store\GeoVillage;
|
||||
use app\common\model\store\GeoBrigade;
|
||||
|
||||
class CityAreaDao extends BaseDao
|
||||
{
|
||||
@ -53,10 +59,35 @@ class CityAreaDao extends BaseDao
|
||||
}
|
||||
}
|
||||
}
|
||||
$query->whereLike('path', $path . '%')->where('name', $street);
|
||||
$query->getVillage('path', $path . '%')->where('name', $street);
|
||||
});
|
||||
}
|
||||
|
||||
public function searchGeo(array $where)
|
||||
{
|
||||
if (!empty($where['street_code'])) {
|
||||
return GeoVillage::getDB()->where('street_code', $where['street_code']);
|
||||
}
|
||||
if (!empty($where['area_code'])) {
|
||||
return GeoStreet::getDB()->where('area_code', $where['area_code']);
|
||||
}
|
||||
if (!empty($where['city_code'])) {
|
||||
return GeoArea::getDB()->where('city_code', $where['city_code']);
|
||||
}
|
||||
if (!empty($where['province_code'])) {
|
||||
return GeoCity::getDB()->where('province_code', $where['province_code']);
|
||||
} else {
|
||||
return GeoProvince::getDB();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function searchBrigade(array $where)
|
||||
{
|
||||
return GeoBrigade::getDB();
|
||||
}
|
||||
|
||||
|
||||
public function getCityList(CityArea $city)
|
||||
{
|
||||
if (!$city->parent_id) return [$city];
|
||||
|
@ -29,6 +29,7 @@ class StoreCartDao extends BaseDao
|
||||
|
||||
const SOURCE_STORE_CLOUD = 101; //店铺内云商品
|
||||
const SOURCE_CLOUD = 102; //云仓内店铺商品
|
||||
const SOURCE_COMMUNITY_RESALE = 201; //转售商品
|
||||
|
||||
protected function getModel(): string
|
||||
{
|
||||
@ -114,7 +115,7 @@ class StoreCartDao extends BaseDao
|
||||
->append(['bc_extension_one', 'bc_extension_two']);
|
||||
},
|
||||
'merchant' => function (Relation $query) use ($uid) {
|
||||
$query->field('mer_id,mer_name,mer_state,mer_avatar,delivery_way,commission_rate,category_id')->with(['coupon' => function ($query) use ($uid) {
|
||||
$query->field('mer_id,mer_name,mer_state,mer_avatar,delivery_way,commission_rate,category_id,credit_buy,settle_cycle,interest_rate')->with(['coupon' => function ($query) use ($uid) {
|
||||
$query->where('uid', $uid);
|
||||
},
|
||||
'config' => function ($query) {
|
||||
|
@ -16,6 +16,7 @@ namespace app\common\dao\store\order;
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
|
||||
/**
|
||||
* Class StoreGroupOrderDao
|
||||
@ -42,11 +43,12 @@ class StoreGroupOrderDao extends BaseDao
|
||||
* @author xaboy
|
||||
* @day 2020/6/11
|
||||
*/
|
||||
public function orderNumber($uid = null)
|
||||
public function orderNumber($uid = null, $productType = 0)
|
||||
{
|
||||
return StoreGroupOrder::when($uid, function ($query, $uid) {
|
||||
$query->where('uid', $uid);
|
||||
})->where('is_del', 0)->where('paid', 0)->count();
|
||||
$storeOrderWhere = StoreOrder::where('activity_type', $productType);
|
||||
return StoreGroupOrder::hasWhere('orderList', $storeOrderWhere)->when($uid, function ($query, $uid) {
|
||||
$query->where('StoreGroupOrder.uid', $uid);
|
||||
})->where('StoreGroupOrder.is_del', 0)->whereRaw("(StoreGroupOrder.paid=0 and status!=12) or (StoreGroupOrder.paid=1 and StoreGroupOrder.pay_type=8 and StoreOrder.status=2)")->count();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,14 +59,18 @@ class StoreGroupOrderDao extends BaseDao
|
||||
*/
|
||||
public function search(array $where)
|
||||
{
|
||||
return StoreGroupOrder::getDB()->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||
$query->where('paid', $where['paid']);
|
||||
return StoreGroupOrder::getDB()->alias('StoreGroupOrder')->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||
if ($where['paid'] == 0) {
|
||||
$query->whereRaw("StoreGroupOrder.paid=0 or (StoreGroupOrder.paid=1 and StoreGroupOrder.pay_type=8)");
|
||||
} else {
|
||||
$query->where('StoreGroupOrder.paid', $where['paid']);
|
||||
}
|
||||
})->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
|
||||
$query->where('uid', $where['uid']);
|
||||
$query->where('StoreGroupOrder.uid', $where['uid']);
|
||||
})->order('create_time DESC')->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
|
||||
$query->where('is_del', $where['is_del']);
|
||||
$query->where('StoreGroupOrder.is_del', $where['is_del']);
|
||||
}, function ($query) {
|
||||
$query->where('is_del', 0);
|
||||
$query->where('StoreGroupOrder.is_del', 0);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ namespace app\common\dao\store\order;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreOrderProduct;
|
||||
use app\common\model\store\order\StoreOrderStatus;
|
||||
@ -91,16 +92,26 @@ class StoreOrderDao extends BaseDao
|
||||
->when(isset($where['activity_type']) && $where['activity_type'] != '', function ($query) use ($where) {
|
||||
$query->where('activity_type', $where['activity_type']);
|
||||
})
|
||||
->when(isset($where['product_type']) && $where['product_type'] != '', function ($query) use ($where) {
|
||||
$query->where('activity_type', $where['product_type']);
|
||||
})
|
||||
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
// 12表示信用购 先货后款
|
||||
switch ($where['status']) {
|
||||
case 0 :
|
||||
$query->whereIn('StoreOrder.status', [0, 9]);
|
||||
$query->whereIn('StoreOrder.status', [0, 9, 12]);
|
||||
break;
|
||||
case -2 :
|
||||
$query->where('paid', 1)->whereNotIn('StoreOrder.status', [10, 11]);
|
||||
$query->where('StoreOrder.paid', 1)->whereNotIn('StoreOrder.status', [10, 11]);
|
||||
break;
|
||||
case 10 :
|
||||
$query->where('paid', 1)->whereIn('StoreOrder.status', [10, 11]);
|
||||
$query->where('StoreOrder.paid', 1)->whereIn('StoreOrder.status', [10, 11]);
|
||||
break;
|
||||
case 2 :
|
||||
$query->where('StoreOrder.paid', 1)->where('StoreOrder.status', $where['status'])->where('pay_type', '<>', StoreGroupOrder::PAY_TYPE_CREDIT_BUY);
|
||||
break;
|
||||
case 20 :
|
||||
$query->where('StoreOrder.paid', 1)->whereIn('StoreOrder.status', [2, 3]);
|
||||
break;
|
||||
default:
|
||||
$query->where('StoreOrder.status', $where['status']);
|
||||
@ -110,7 +121,7 @@ class StoreOrderDao extends BaseDao
|
||||
->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreOrder.uid', $where['uid']);
|
||||
})
|
||||
->when(isset($where['is_user']) && $where['is_user'] !== '', function ($query) use ($where) {
|
||||
->when(isset($where['is_user']) && $where['is_user'] !== 0, function ($query) use ($where) {
|
||||
$query->where(function($query) {
|
||||
$query->where('order_type',0)->whereOr(function($query){
|
||||
$query->where('order_type',1)->where('main_id',0);
|
||||
@ -503,7 +514,7 @@ class StoreOrderDao extends BaseDao
|
||||
{
|
||||
return StoreOrderStatus::getDB()->alias('A')->leftJoin('StoreOrder B', 'A.order_id = B.order_id')
|
||||
->where('A.change_type', 'take')
|
||||
->where('A.change_time', '<', $end)->where('B.paid', 1)->where('B.status', 2)
|
||||
->where('A.change_time', '<', $end)->where('B.paid', 1)->where('B.status', 2)->where('B.pay_type', '<>', StoreGroupOrder::PAY_TYPE_CREDIT_BUY)
|
||||
->column('A.order_id');
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,9 @@ class StoreRefundOrderDao extends BaseDao
|
||||
})->when(isset($where['order_sn']) && $where['order_sn'] !== '', function ($query) use ($where) {
|
||||
$ids = StoreOrder::where('order_sn','like','%'.$where['order_sn'].'%')->column('order_id');
|
||||
$query->where('order_id','in',$ids);
|
||||
})->when(isset($where['product_type']) && $where['product_type'] !== '', function ($query) use ($where) {
|
||||
$ids = StoreOrder::where('uid', $where['uid'])->where('activity_type', $where['product_type'])->column('order_id');
|
||||
$query->where('order_id','in',$ids);
|
||||
})->when(isset($where['refund_order_sn']) && $where['refund_order_sn'] !== '', function ($query) use ($where) {
|
||||
$query->where('refund_order_sn', 'like', '%' . $where['refund_order_sn'] . '%');
|
||||
})->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||
|
@ -155,6 +155,18 @@ class ProductAttrValueDao extends BaseDao
|
||||
]);
|
||||
}
|
||||
|
||||
public function incSales(int $productId, string $unique, int $number)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->where('unique', $unique)->update([
|
||||
'sales' => Db::raw('sales+' . $number)
|
||||
]);
|
||||
}
|
||||
|
||||
public function descSales(int $productId, string $unique, int $number)
|
||||
{
|
||||
model::getDB()->where('product_id', $productId)->where('unique', $unique)->where('sales', '>=', $number)->dec('sales', $number)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param string $sku
|
||||
|
@ -151,6 +151,9 @@ class ProductDao extends BaseDao
|
||||
});
|
||||
}
|
||||
})
|
||||
->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('Product.keyword', "%{$where['keyword']}%");
|
||||
})
|
||||
->when(isset($where['mer_labels']) && $where['mer_labels'] !== '', function ($query) use ($where) {
|
||||
$query->whereLike('U.mer_labels', "%,{$where['mer_labels']},%");
|
||||
})
|
||||
@ -318,6 +321,18 @@ class ProductDao extends BaseDao
|
||||
]);
|
||||
}
|
||||
|
||||
public function incSales(int $productId, int $number)
|
||||
{
|
||||
return model::getDB()->where('product_id', $productId)->update([
|
||||
'sales' => Db::raw('sales+' . $number)
|
||||
]);
|
||||
}
|
||||
|
||||
public function descSales(int $productId, int $number)
|
||||
{
|
||||
model::getDB()->where('product_id', $productId)->where('sales', '>=', $number)->dec('sales', $number)->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $productId
|
||||
* @param int $inc
|
||||
|
@ -112,9 +112,8 @@ class FinancialRecordDao extends BaseDao
|
||||
} else {
|
||||
$query->whereMonth('create_time',$date);
|
||||
}
|
||||
|
||||
$count = $query->group('order_id')->count();
|
||||
$number = $query->sum('number');
|
||||
$count = $query->group('order_id')->where('number', '<>', 0)->count();
|
||||
$number = $query->where('number', '<>', 0)->sum('number');
|
||||
|
||||
return [$count,$number];
|
||||
}
|
||||
|
@ -49,6 +49,9 @@ class MerchantDao extends BaseDao
|
||||
->when($is_del !== null, function ($query) use ($is_del) {
|
||||
$query->where('is_del', $is_del);
|
||||
})
|
||||
->when(isset($where['credit_buy']) && $where['credit_buy'] !== '', function ($query) use ($where) {
|
||||
$query->where('credit_buy', $where['credit_buy']);
|
||||
})
|
||||
->when(isset($where['is_trader']) && $where['is_trader'] !== '', function ($query) use ($where) {
|
||||
$query->where('is_trader', $where['is_trader']);
|
||||
})
|
||||
|
@ -34,7 +34,7 @@ class SystemNoticeConfigDao extends BaseDao
|
||||
|
||||
public function getNoticeStatusByConstKey(string $key)
|
||||
{
|
||||
$value = $this->getModel()::getDb()->where('const_key',$key)->field('notice_sys,notice_wechat,notice_routine,notice_sms')->find();
|
||||
$value = $this->getModel()::getDb()->where('const_key',$key)->field('notice_sys,notice_wechat,notice_routine,notice_sms,notice_app')->find();
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ namespace app\common\dao\user;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\GeoVillage;
|
||||
use app\common\model\user\UserAddress as model;
|
||||
|
||||
class UserAddressDao extends BaseDao
|
||||
@ -30,6 +31,10 @@ class UserAddressDao extends BaseDao
|
||||
return model::class;
|
||||
}
|
||||
|
||||
public function villageExists($field, $value): bool
|
||||
{
|
||||
return ((GeoVillage::getDB())->where($field,$value)->count()) > 0;
|
||||
}
|
||||
|
||||
public function userFieldExists($field, $value,$uid): bool
|
||||
{
|
||||
@ -45,4 +50,5 @@ class UserAddressDao extends BaseDao
|
||||
{
|
||||
return (($this->getModel()::getDB())->where('uid',$uid));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ namespace app\common\model\community;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\product\Spu;
|
||||
use app\common\model\store\Resale;
|
||||
use app\common\model\system\Relevance;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\system\RelevanceRepository;
|
||||
@ -171,4 +172,9 @@ class Community extends BaseModel
|
||||
$query->where('community_id', '<>',$value);
|
||||
}
|
||||
|
||||
public function resale()
|
||||
{
|
||||
return $this->hasMany(Resale::class, 'community_id','community_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
26
app/common/model/store/Entrust.php
Normal file
26
app/common/model/store/Entrust.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\store;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\product\Spu;
|
||||
|
||||
class Entrust extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'entrust';
|
||||
}
|
||||
|
||||
public function spu()
|
||||
{
|
||||
return $this->hasOne(Spu::class, 'product_id','product_id');
|
||||
}
|
||||
|
||||
}
|
30
app/common/model/store/GeoBrigade.php
Normal file
30
app/common/model/store/GeoBrigade.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\store;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class GeoBrigade extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'geo_brigade';
|
||||
}
|
||||
}
|
31
app/common/model/store/GeoCity.php
Normal file
31
app/common/model/store/GeoCity.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\store;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class GeoCity extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'geo_city';
|
||||
}
|
||||
|
||||
}
|
30
app/common/model/store/GeoProvince.php
Normal file
30
app/common/model/store/GeoProvince.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\store;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class GeoProvince extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'geo_province';
|
||||
}
|
||||
}
|
30
app/common/model/store/GeoStreet.php
Normal file
30
app/common/model/store/GeoStreet.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\store;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class GeoStreet extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'geo_street';
|
||||
}
|
||||
}
|
30
app/common/model/store/GeoVillage.php
Normal file
30
app/common/model/store/GeoVillage.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\common\model\store;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class GeoVillage extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'geo_village';
|
||||
}
|
||||
}
|
26
app/common/model/store/Resale.php
Normal file
26
app/common/model/store/Resale.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\store;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\product\Spu;
|
||||
|
||||
class Resale extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'resale';
|
||||
}
|
||||
|
||||
public function spu()
|
||||
{
|
||||
return $this->hasOne(Spu::class, 'product_id','product_id');
|
||||
}
|
||||
|
||||
}
|
@ -66,7 +66,7 @@ class PresellOrder extends BaseModel
|
||||
return $status;
|
||||
}
|
||||
|
||||
public function getCombinePayParams()
|
||||
public function getCombinePayParams($attach = 'presell')
|
||||
{
|
||||
return [
|
||||
'order_sn' => $this->presell_order_sn,
|
||||
@ -77,17 +77,17 @@ class PresellOrder extends BaseModel
|
||||
'sub_mchid' => $this->merchant->sub_mchid,
|
||||
]
|
||||
],
|
||||
'attach' => 'presell',
|
||||
'attach' => $attach,
|
||||
'body' => '尾款支付',
|
||||
];
|
||||
}
|
||||
|
||||
public function getPayParams($return_url = '')
|
||||
public function getPayParams($return_url = '', $attach = 'presell')
|
||||
{
|
||||
$params = [
|
||||
'order_sn' => $this->presell_order_sn,
|
||||
'pay_price' => $this->pay_price,
|
||||
'attach' => 'presell',
|
||||
'attach' => $attach,
|
||||
'body' => '尾款支付'
|
||||
];
|
||||
if ($return_url) {
|
||||
|
@ -155,6 +155,9 @@ class StoreCart extends BaseModel
|
||||
'activity_id' => $this->source_id,
|
||||
'product_type' => $this->product_type,
|
||||
];
|
||||
if ($this->product_type == 98) {
|
||||
$where['product_id'] = $this->product_id;
|
||||
}
|
||||
} else {
|
||||
$where = [
|
||||
'product_id' => $this->product_id,
|
||||
|
@ -21,6 +21,12 @@ use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
class StoreGroupOrder extends BaseModel
|
||||
{
|
||||
|
||||
const PAY_TYPE_BALANCE = 0; //余额支付
|
||||
const PAY_TYPE_WECHAT = 1; //微信支付
|
||||
const PAY_TYPE_ROUTINE = 2; //小程序支付
|
||||
const PAY_TYPE_H5 = 3; //H5支付
|
||||
const PAY_TYPE_CREDIT_BUY = 8; //信用购 先货后款
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'group_order_id';
|
||||
@ -70,12 +76,12 @@ class StoreGroupOrder extends BaseModel
|
||||
return $value ? implode(',', $value) : '';
|
||||
}
|
||||
|
||||
public function getCombinePayParams()
|
||||
public function getCombinePayParams($attach = 'order')
|
||||
{
|
||||
$params = [
|
||||
'order_sn' => $this->group_order_sn,
|
||||
'sub_orders' => [],
|
||||
'attach' => 'order',
|
||||
'attach' => $attach,
|
||||
'body' => '订单支付',
|
||||
];
|
||||
foreach ($this->orderList as $order) {
|
||||
@ -91,12 +97,12 @@ class StoreGroupOrder extends BaseModel
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function getPayParams($return_url = '')
|
||||
public function getPayParams($return_url = '', $attach = 'order')
|
||||
{
|
||||
$params = [
|
||||
'order_sn' => $this->group_order_sn,
|
||||
'pay_price' => $this->pay_price,
|
||||
'attach' => 'order',
|
||||
'attach' => $attach,
|
||||
'body' => '订单支付'
|
||||
];
|
||||
if ($return_url) {
|
||||
@ -104,4 +110,10 @@ class StoreGroupOrder extends BaseModel
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
public function interest()
|
||||
{
|
||||
return $this->hasOne(StoreOrderInterest::class, 'group_order_id', 'group_order_id');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,11 @@ use app\common\repositories\store\MerchantTakeRepository;
|
||||
class StoreOrder extends BaseModel
|
||||
{
|
||||
|
||||
const STATUS_WAIT_CONFIRM = 12; //待确认
|
||||
const STATUS_WAIT_PAY = 0; //待支付
|
||||
const STATUS_WAIT_COMMENT = 2; //待评价
|
||||
const STATUS_FINISH = 3; //已完成
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'order_id';
|
||||
@ -177,4 +182,15 @@ class StoreOrder extends BaseModel
|
||||
{
|
||||
return StoreRefundOrder::where('order_id',$this->order_id)->where('status',3)->sum('refund_price');
|
||||
}
|
||||
|
||||
public function interest()
|
||||
{
|
||||
return $this->hasOne(StoreOrderInterest::class, 'order_id', 'order_id');
|
||||
}
|
||||
|
||||
public function allowCreditPay()
|
||||
{
|
||||
return $this->pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && $this->status == self::STATUS_WAIT_PAY;
|
||||
}
|
||||
|
||||
}
|
||||
|
39
app/common/model/store/order/StoreOrderInterest.php
Normal file
39
app/common/model/store/order/StoreOrderInterest.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\store\order;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class StoreOrderInterest extends BaseModel
|
||||
{
|
||||
|
||||
const STATUS_SETTLED = 1; //已结算
|
||||
const STATUS_UNSETTLED = 0; //未结算
|
||||
const STATUS_DELETED = -1; //已删除
|
||||
|
||||
public static function tablePk(): ?string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'store_order_interest';
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算利息
|
||||
* @return string
|
||||
*/
|
||||
public function calculateInterest()
|
||||
{
|
||||
if ($this->start_time == '0000-00-00 00:00:00') {
|
||||
return 0;
|
||||
}
|
||||
$days = ceil((time() - strtotime($this->start_time)) / 86400);
|
||||
$days = max($days ,0);
|
||||
$money = bcmul($this->total_price, ($this->rate / 100), 3);
|
||||
return bcmul($days, $money, 2);
|
||||
}
|
||||
|
||||
}
|
@ -40,6 +40,10 @@ class Product extends BaseModel
|
||||
|
||||
const IS_SHOW = 1; //上架
|
||||
const IS_NOT_SHOW = 0; //下架
|
||||
|
||||
const TYPE_NORMAL = 0; //普通商品
|
||||
const TYPE_PURCHASE = 98; //采购商品
|
||||
|
||||
/**
|
||||
* @Author:Qinii
|
||||
* @Date: 2020/5/8
|
||||
|
@ -43,7 +43,7 @@ class ProductAttrValue extends BaseModel
|
||||
|
||||
public function getDetailAttr($value)
|
||||
{
|
||||
return json_decode($value);
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
public function product()
|
||||
|
36
app/common/model/store/product/PurchaseRecord.php
Normal file
36
app/common/model/store/product/PurchaseRecord.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\store\product;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
|
||||
class PurchaseRecord extends BaseModel
|
||||
{
|
||||
|
||||
public static function tablePk(): string
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
public static function tableName(): string
|
||||
{
|
||||
return 'purchase_record';
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->hasOne(Product::class, 'product_id', 'product_id');
|
||||
}
|
||||
|
||||
public function supplier()
|
||||
{
|
||||
return $this->hasOne(Merchant::class, 'mer_id', 'supplier_mer_id');
|
||||
}
|
||||
|
||||
public function merchant()
|
||||
{
|
||||
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
|
||||
}
|
||||
|
||||
}
|
@ -35,6 +35,7 @@ class Merchant extends BaseModel
|
||||
const TypeTeamServer = 14; //小组服务团
|
||||
const TypeVillageServer = 15; //村服务团队
|
||||
const TypeTownServer = 16; //镇服务团队
|
||||
const TypeTownSupplyChain = 17; //镇级供应链
|
||||
|
||||
const TypeMap = [
|
||||
self::TypeStore => '镇街店铺',
|
||||
@ -44,16 +45,19 @@ class Merchant extends BaseModel
|
||||
self::TypeTeamServer => '小组服务团',
|
||||
self::TypeVillageServer => '村服务团队',
|
||||
self::TypeTownServer => '镇服务团队',
|
||||
self::TypeTownSupplyChain => '镇级供应链',
|
||||
];
|
||||
const AllowApply = [ //允许申请的类型
|
||||
self::TypeStore,
|
||||
self::TypeSupplyChain,
|
||||
self::TypeTownSupplyChain,
|
||||
];
|
||||
const AllowDisplay = [ //允许展示的类型
|
||||
self::TypeStore,
|
||||
self::TypeCloudWarehouse,
|
||||
self::TypeSupplyChain,
|
||||
self::TypePlatform,
|
||||
self::TypeTownSupplyChain,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,15 @@
|
||||
namespace app\common\repositories\community;
|
||||
|
||||
use app\common\dao\community\CommunityDao;
|
||||
use app\common\dao\store\order\StoreCartDao;
|
||||
use app\common\model\community\Community;
|
||||
use app\common\model\store\order\StoreCart;
|
||||
use app\common\model\store\product\ProductAttrValue;
|
||||
use app\common\model\store\product\PurchaseRecord;
|
||||
use app\common\model\store\Resale;
|
||||
use app\common\model\store\Entrust;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\store\order\StoreCartRepository;
|
||||
use app\common\repositories\store\order\StoreOrderProductRepository;
|
||||
use app\common\repositories\store\product\SpuRepository;
|
||||
use app\common\repositories\system\RelevanceRepository;
|
||||
@ -40,6 +48,12 @@ class CommunityRepository extends BaseRepository
|
||||
|
||||
public const COMMUNIT_TYPE_FONT = '1';
|
||||
public const COMMUNIT_TYPE_VIDEO = '2';
|
||||
public const COMMUNITY_TYPE_RESALE = 3; //转售贴
|
||||
public const COMMUNITY_TYPE_ENTRUST = 4; //委托销售贴
|
||||
public const RESALE_TYPE_STORE = 1; //到店核销
|
||||
public const RESALE_TYPE_DELIVER = 2; //快递配送
|
||||
public const RESALE_TYPE_TRANSFER = 1; //调货
|
||||
public const RESALE_TYPE_DISCOUNT = 2; //打折
|
||||
|
||||
/**
|
||||
* CommunityRepository constructor.
|
||||
@ -81,6 +95,11 @@ class CommunityRepository extends BaseRepository
|
||||
]);
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->select();
|
||||
foreach($list as $key=>$val) {
|
||||
$merInfo = Db::name('StoreService')->alias('ss')->leftJoin('Merchant m','ss.mer_id = M.mer_id')->where('ss.uid', $val['uid'])->field('m.mer_avatar, m.mer_name')->find();
|
||||
$list[$key]['mer_name'] = $merInfo['mer_name'] ?? '';
|
||||
$list[$key]['mer_avatar'] = $merInfo['mer_avatar'] ?? '';
|
||||
}
|
||||
return compact('count','list');
|
||||
}
|
||||
|
||||
@ -88,10 +107,12 @@ class CommunityRepository extends BaseRepository
|
||||
public function getApiList(array $where, int $page, int $limit, $userInfo)
|
||||
{
|
||||
$config = systemConfig("community_app_switch");
|
||||
if (!isset($where['is_type']) && $config) $where['is_type'] = $config;
|
||||
// if (!isset($where['is_type']) && $config) $where['is_type'] = is_array($config) ? implode(',', $config) : $config;
|
||||
if (empty($where['is_type'])) $where['is_type'] = '1,2';
|
||||
$where['is_del'] = 0;
|
||||
|
||||
$query = $this->dao->search($where)->order('start DESC,Community.create_time DESC,community_id DESC');
|
||||
$query = $this->dao->search($where)->when(in_array(self::COMMUNITY_TYPE_RESALE, explode(',', $where['is_type'])), function ($query) {
|
||||
$query->where('is_sale', 0);
|
||||
})->order('start DESC,Community.create_time DESC,community_id DESC');
|
||||
$query->with([
|
||||
'author' => function($query) use($userInfo){
|
||||
$query->field('uid,real_name,status,avatar,nickname,count_start');
|
||||
@ -110,13 +131,30 @@ class CommunityRepository extends BaseRepository
|
||||
],
|
||||
'is_fans' => function($query) use($userInfo){
|
||||
$query->where('left_id',$userInfo->uid?? 0);
|
||||
}
|
||||
},
|
||||
'resale',
|
||||
]);
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->setOption('field',[])
|
||||
->field('community_id,title,image,topic_id,Community.count_start,count_reply,start,Community.create_time,Community.uid,Community.status,is_show,content,video_link,is_type,refusal')
|
||||
->field('community_id,title,image,resale_type,topic_id,Community.count_start,count_reply,start,Community.create_time,Community.uid,Community.status,is_show,content,video_link,is_type,refusal')
|
||||
->select()->append(['time']);
|
||||
|
||||
if ($list) $list = $list->toArray();
|
||||
foreach ($list as $k => $item) {
|
||||
if ($item['is_type'] == self::COMMUNITY_TYPE_RESALE) {
|
||||
$list[$k]['total_price'] = '0';
|
||||
foreach ($item['resale'] as $value) {
|
||||
$list[$k]['total_price'] = bcadd($list[$k]['total_price'], bcmul($value['price'], $value['number'], 2), 2);
|
||||
}
|
||||
$list[$k]['mer_name'] = '';
|
||||
$list[$k]['mer_avatar'] = '';
|
||||
$merInfo = Db::name('StoreService')->alias('ss')->leftJoin('Merchant m','ss.mer_id = M.mer_id')->where('ss.uid', $item['uid'])->field('m.mer_avatar, m.mer_name')->find();
|
||||
if ($merInfo) {
|
||||
$list[$k]['mer_name'] = $merInfo['mer_name'];
|
||||
$list[$k]['mer_avatar'] = $merInfo['mer_avatar'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return compact('count','list');
|
||||
}
|
||||
|
||||
@ -186,7 +224,7 @@ class CommunityRepository extends BaseRepository
|
||||
];
|
||||
$config = systemConfig("community_app_switch");
|
||||
if ($config) $where['is_type'] = $config;
|
||||
return $this->dao->getSearch($where)->with([
|
||||
$info = $this->dao->getSearch($where)->with([
|
||||
'author' => function($query) {
|
||||
$query->field('uid,real_name,status,avatar,nickname,count_start');
|
||||
},
|
||||
@ -194,6 +232,12 @@ class CommunityRepository extends BaseRepository
|
||||
'category',
|
||||
'relevance.spu'
|
||||
])->find();
|
||||
if ($info){
|
||||
$merInfo = Db::name('StoreService')->alias('ss')->leftJoin('Merchant m','ss.mer_id = M.mer_id')->where('ss.uid', $info['uid'])->field('m.mer_avatar, m.mer_name')->find();
|
||||
$info['mer_name'] = $merInfo['mer_name'] ?? '';
|
||||
$info['mer_avatar'] = $merInfo['mer_avatar'] ?? '';
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -236,6 +280,11 @@ class CommunityRepository extends BaseRepository
|
||||
'is_start' => function ($query) use ($user) {
|
||||
$query->where('left_id', $user->uid ?? '');
|
||||
},
|
||||
'resale' => [
|
||||
// 'spu' => function ($query) {
|
||||
// $query->field('spu_id,store_name,image,price,product_type,activity_id,product_id');
|
||||
// }
|
||||
],
|
||||
])->hidden(['is_del'])->find();
|
||||
|
||||
if (!$data) throw new ValidateException('内容不存在,可能已被删除了哦~');
|
||||
@ -249,6 +298,28 @@ class CommunityRepository extends BaseRepository
|
||||
'type' => RelevanceRepository::TYPE_COMMUNITY_FANS,
|
||||
]);
|
||||
$data['is_fans'] = $is_fans;
|
||||
if ($data['is_type'] == self::COMMUNITY_TYPE_RESALE) {
|
||||
$data['total_price'] = '0';
|
||||
foreach ($data['resale'] as $k=>$value) {
|
||||
$data['total_price'] = bcadd($data['total_price'], bcmul($value['price'], $value['number'], 2), 2);
|
||||
$attrInfo = Db::name('StoreProduct')->alias('sp')->leftJoin('StoreProductAttrValue sv','sp.product_id = sv.product_id')->where('sv.unique', $value['product_attr_unique'])->field('sv.detail, sv.sku, sv.sales, sp.store_name, sp.image')->find();
|
||||
$data['resale'][$k]['sku'] = $attrInfo['sku'] ?? '';
|
||||
$data['resale'][$k]['sales'] = $attrInfo['sales'] ?? 0;
|
||||
$data['resale'][$k]['store_name'] = $attrInfo['store_name'] ?? '';
|
||||
$data['resale'][$k]['image'] = $attrInfo['image'] ?? '';
|
||||
}
|
||||
$data['mer_avatar'] = '';
|
||||
$data['mer_name'] = '';
|
||||
$data['sales'] = 0;
|
||||
$data['care_count'] = 0;
|
||||
$merInfo = Db::name('StoreService')->alias('ss')->leftJoin('Merchant m','ss.mer_id = m.mer_id')->where('ss.uid', $data['uid'])->field('m.mer_avatar, m.mer_name, m.sales, m.care_count')->find();
|
||||
if ($merInfo) {
|
||||
$data['mer_avatar'] = $merInfo['mer_avatar'];
|
||||
$data['mer_name'] = $merInfo['mer_name'];
|
||||
$data['sales'] = $merInfo['sales'];
|
||||
$data['care_count'] = $merInfo['care_count'];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
@ -302,6 +373,12 @@ class CommunityRepository extends BaseRepository
|
||||
return Db::transaction(function () use($data) {
|
||||
$community = $this->dao->create($data);
|
||||
if ($data['spu_id'])$this->joinProduct($community->community_id,$data['spu_id']);
|
||||
if ($data['product_info'] && $data['is_type'] == self::COMMUNITY_TYPE_RESALE) {
|
||||
$this->resale($community->community_id, $data['product_info'], $data['resale_type'] ?? 0);
|
||||
}
|
||||
if ($data['product_info'] && $data['is_type'] == self::COMMUNITY_TYPE_ENTRUST) {
|
||||
$this->entrust($community->community_id, $data['product_info'], $data['entrust_mer_id'] ?? 0, $data['entrust_day'] ?? 0);
|
||||
}
|
||||
event('community.create',compact('community'));
|
||||
return $community->community_id;
|
||||
});
|
||||
@ -326,9 +403,16 @@ class CommunityRepository extends BaseRepository
|
||||
|
||||
Db::transaction(function () use($id, $data) {
|
||||
$spuId = $data['spu_id'];
|
||||
unset($data['spu_id']);
|
||||
$productInfo = $data['product_info'];
|
||||
unset($data['spu_id'], $data['product_info']);
|
||||
$community = $this->dao->update($id, $data);
|
||||
if ($spuId) $this->joinProduct($id, $spuId);
|
||||
if ($productInfo && $data['is_type'] == self::COMMUNITY_TYPE_RESALE) {
|
||||
$this->resale($id, $productInfo, $data['resale_type'] ?? 0);
|
||||
}
|
||||
if ($productInfo && $data['is_type'] == self::COMMUNITY_TYPE_ENTRUST) {
|
||||
$this->entrust($community->community_id, $data['product_info'], $data['entrust_mer_id'] ?? 0, $data['entrust_day'] ?? 0);
|
||||
}
|
||||
event('community.update.before',compact('id','community'));
|
||||
});
|
||||
}
|
||||
@ -460,11 +544,12 @@ class CommunityRepository extends BaseRepository
|
||||
$ret = $this->dao->get($id);
|
||||
event('community.status.before',compact('id','data'));
|
||||
Db::transaction(function () use($ret,$id, $data) {
|
||||
|
||||
if ($data['status'] == 1) {
|
||||
$make = app()->make(UserBrokerageRepository::class);
|
||||
$make->incMemberValue($ret['uid'], 'member_community_num', $id);
|
||||
Db::name('resale')->where('community_id', $id)->update(['float_rate' => $data['float_rate'] ?? 0]);
|
||||
}
|
||||
unset($data['float_rate']);
|
||||
$data['status_time'] = date('Y-m-d H:i;s', time());
|
||||
$this->dao->update($id, $data);
|
||||
event('community.status',compact('id'));
|
||||
@ -506,5 +591,186 @@ class CommunityRepository extends BaseRepository
|
||||
return $make->getWechatQrcodePath($name, $link, false, $key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转售贴
|
||||
* @param $id
|
||||
* @param array $data
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function resale($id, array $data, $resaleType = 0)
|
||||
{
|
||||
|
||||
$insert = [];
|
||||
foreach ($data as $value) {
|
||||
if (isset($value['id'])) {
|
||||
$resale = Resale::find($value['id']);
|
||||
unset($value['product_attr_unique']);
|
||||
$resale->update($value);
|
||||
continue;
|
||||
}
|
||||
$purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find();
|
||||
// $exist = Resale::where('purchase_record_id', $purchaseRecord['id'])->find();
|
||||
// if ($exist) {
|
||||
// throw new ValidateException('已发起转售');
|
||||
// }
|
||||
$totalNumber = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('number');
|
||||
$totalSalesVolume = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('sales_volume');
|
||||
if (empty($purchaseRecord) || ($totalNumber - $totalSalesVolume) <= 0) {
|
||||
throw new ValidateException('进货记录不存在或已售罄');
|
||||
}
|
||||
if (($totalNumber - $totalSalesVolume) < $value['number']) {
|
||||
throw new ValidateException('库存不足');
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
$insert[] = [
|
||||
'community_id' => $id,
|
||||
'purchase_record_id' => $purchaseRecord['id'],
|
||||
'product_id' => $purchaseRecord['product_id'],
|
||||
'product_attr_unique' => $purchaseRecord['unique'],
|
||||
'mer_id' => $purchaseRecord['mer_id'],
|
||||
'number' => $value['number'],
|
||||
'price' => $value['price'],
|
||||
'resale_type' => $resaleType,
|
||||
'deliver_method' => $value['deliver_method'] ?? '',
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
$purchaseRecord->product->stock -= $value['number'];
|
||||
$purchaseRecord->product->save();
|
||||
$attrValue = ProductAttrValue::where('product_id', $purchaseRecord['product_id'])->where('unique', $purchaseRecord['unique'])->find();
|
||||
$attrValue->stock -= $value['number'];
|
||||
$attrValue->save();
|
||||
}
|
||||
if ($insert) {
|
||||
Resale::getInstance()->insertAll($insert);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 委托贴
|
||||
* @param $id
|
||||
* @param array $data
|
||||
* @return void
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function entrust($id, array $data, $entrustMerId, $entrustDay)
|
||||
{
|
||||
$insert = [];
|
||||
foreach ($data as $value) {
|
||||
if (isset($value['id'])) {
|
||||
$entrustInfo = Entrust::find($value['id']);
|
||||
unset($value['product_attr_unique']);
|
||||
$entrustInfo->update($value);
|
||||
continue;
|
||||
}
|
||||
$purchaseRecord = PurchaseRecord::where('unique', $value['product_attr_unique'])->find();
|
||||
$totalNumber = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('number');
|
||||
$totalSalesVolume = PurchaseRecord::where('unique', $value['product_attr_unique'])->sum('sales_volume');
|
||||
if (empty($purchaseRecord) || ($totalNumber - $totalSalesVolume) <= 0) {
|
||||
throw new ValidateException('进货记录不存在或已售罄');
|
||||
}
|
||||
if (($totalNumber - $totalSalesVolume) < $value['number']) {
|
||||
throw new ValidateException('库存不足');
|
||||
}
|
||||
|
||||
if ($value) {
|
||||
$insert[] = [
|
||||
'community_id' => $id,
|
||||
'purchase_record_id' => $purchaseRecord['id'],
|
||||
'product_id' => $purchaseRecord['product_id'],
|
||||
'product_attr_unique' => $purchaseRecord['unique'],
|
||||
'mer_id' => $purchaseRecord['mer_id'],
|
||||
'entrust_mer_id' => $entrustMerId,
|
||||
'entrust_day' => $entrustDay,
|
||||
'number' => $value['number'],
|
||||
'price' => $value['price'],
|
||||
'update_time' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
$purchaseRecord->product->stock -= $value['number'];
|
||||
$purchaseRecord->product->save();
|
||||
$attrValue = ProductAttrValue::where('product_id', $purchaseRecord['product_id'])->where('unique', $purchaseRecord['unique'])->find();
|
||||
$attrValue->stock -= $value['number'];
|
||||
$attrValue->save();
|
||||
}
|
||||
if ($insert) {
|
||||
Entrust::getInstance()->insertAll($insert);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转售加入购物车
|
||||
* @param $uid
|
||||
* @param $id
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function addCart($uid, $id)
|
||||
{
|
||||
$where = [
|
||||
$this->dao->getPk() => $id,
|
||||
'is_del' => 0
|
||||
];
|
||||
$community = $this->dao->getSearch($where)->with('resale')->find()->toArray();
|
||||
if (empty($community) || $community['is_sale'] != 0) {
|
||||
throw new ValidateException('转售数据不存在或已售出');
|
||||
}
|
||||
if (empty($community['resale'])) {
|
||||
throw new ValidateException('转售数据不存在');
|
||||
}
|
||||
StoreCart::startTrans();
|
||||
try {
|
||||
/** @var StoreCartRepository $cartRepo */
|
||||
$cartRepo = app()->make(StoreCartRepository::class);
|
||||
$cartIds = [];
|
||||
foreach ($community['resale'] as $item) {
|
||||
$data = [
|
||||
'uid' => $uid,
|
||||
'mer_id' => $item['mer_id'],
|
||||
'product_type' => 98,
|
||||
'product_id' => $item['product_id'],
|
||||
'product_attr_unique' => $item['product_attr_unique'],
|
||||
'cart_num' => $item['number'],
|
||||
'source' => StoreCartDao::SOURCE_COMMUNITY_RESALE,
|
||||
'source_id' => $community['community_id'],
|
||||
];
|
||||
$cart = $cartRepo->create($data);
|
||||
$cartIds[] = $cart['cart_id'];
|
||||
}
|
||||
if (empty($cartIds)) {
|
||||
throw new ValidateException('加入购物车出错');
|
||||
}
|
||||
StoreCart::commit();
|
||||
return $cartIds;
|
||||
} catch (\Exception $exception) {
|
||||
StoreCart::rollback();
|
||||
throw new ValidateException('下单出错');
|
||||
}
|
||||
}
|
||||
|
||||
public function saleOrCancel($id, $status = 1)
|
||||
{
|
||||
$where = [
|
||||
$this->dao->getPk() => $id,
|
||||
'is_del' => 0
|
||||
];
|
||||
$community = $this->dao->getSearch($where)->with('resale')->find();
|
||||
$community->is_sale = $status;
|
||||
$community->save();
|
||||
foreach ($community->resale as $item) {
|
||||
$item->status = $status;
|
||||
$item->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,16 @@ class CityAreaRepository extends BaseRepository
|
||||
return $this->search(['pid' => $pid])->select();
|
||||
}
|
||||
|
||||
public function getGeoChildren($where)
|
||||
{
|
||||
return $this->searchGeo($where)->select();
|
||||
}
|
||||
|
||||
public function getBrigade($where)
|
||||
{
|
||||
return $this->searchBrigade($where)->select();
|
||||
}
|
||||
|
||||
public function getList($where)
|
||||
{
|
||||
return $this->dao->getSearch($where)->with(['parent'])->order('id ASC')->select()->append(['children','hasChildren']);
|
||||
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\model\store\product\PurchaseRecord;
|
||||
use app\common\repositories\BaseRepository;
|
||||
|
||||
class PurchaseRecordRepository extends BaseRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* 扣销量
|
||||
* @param $productId
|
||||
* @param $unique
|
||||
* @param $desc
|
||||
* @return void
|
||||
*/
|
||||
public function descSalesVolume($productId, $unique, $desc)
|
||||
{
|
||||
while ($desc > 0) {
|
||||
$purchaseRecord = $this->getPurchaseRecord2($productId, $unique);
|
||||
if (!$purchaseRecord) {
|
||||
break;
|
||||
}
|
||||
$number = min($desc, $purchaseRecord->sales_volume);
|
||||
$purchaseRecord->sales_volume -= $number;
|
||||
$purchaseRecord->save();
|
||||
$desc -= $number;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加销量
|
||||
* @param $productId
|
||||
* @param $unique
|
||||
* @param $inc
|
||||
* @return void
|
||||
*/
|
||||
public function incSalesVolume($productId, $unique, $inc)
|
||||
{
|
||||
while ($inc > 0) {
|
||||
$purchaseRecord = $this->getPurchaseRecord($productId, $unique);
|
||||
if (!$purchaseRecord) {
|
||||
break;
|
||||
}
|
||||
$stock = $purchaseRecord->number - $purchaseRecord->sales_volume;
|
||||
$purchaseRecord->sales_volume += min($inc, $stock);
|
||||
$purchaseRecord->save();
|
||||
$inc -= $stock;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPurchaseRecord($productId, $unique)
|
||||
{
|
||||
return PurchaseRecord::where('product_id', $productId)->where('unique', $unique)->whereRaw('sales_volume<number')->order('id asc')->find();
|
||||
}
|
||||
|
||||
public function getPurchaseRecord2($productId, $unique)
|
||||
{
|
||||
return PurchaseRecord::where('product_id', $productId)->where('unique', $unique)->where('sales_volume', '>', 0)->order('id desc')->find();
|
||||
}
|
||||
|
||||
}
|
@ -15,12 +15,16 @@ namespace app\common\repositories\store\order;
|
||||
|
||||
|
||||
use app\common\dao\store\order\StoreGroupOrderDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreOrderInterest;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
||||
use app\common\repositories\user\UserBillRepository;
|
||||
use app\common\repositories\user\UserRepository;
|
||||
use crmeb\jobs\CancelGroupOrderJob;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Queue;
|
||||
@ -60,11 +64,41 @@ class StoreGroupOrderRepository extends BaseRepository
|
||||
*/
|
||||
public function getList(array $where, $page, $limit)
|
||||
{
|
||||
$query = $this->search($where);
|
||||
$query = StoreGroupOrder::getDB()->alias('StoreGroupOrder');
|
||||
if (isset($where['product_type'])) {
|
||||
$storeOrderWhere = StoreOrder::where('activity_type', $where['product_type']);
|
||||
$query->hasWhere('orderList', $storeOrderWhere);
|
||||
}
|
||||
$query->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
|
||||
if ($where['paid'] == 0) {
|
||||
$query->whereRaw("(StoreGroupOrder.paid=0 and status!=12) or (StoreGroupOrder.paid=1 and StoreGroupOrder.pay_type=8 and StoreOrder.status=2)");
|
||||
} else {
|
||||
$query->where('StoreGroupOrder.paid', $where['paid']);
|
||||
}
|
||||
})->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreGroupOrder.uid', $where['uid']);
|
||||
})->order('create_time DESC')->when(isset($where['is_del']) && $where['is_del'] !== '', function ($query) use ($where) {
|
||||
$query->where('StoreGroupOrder.is_del', $where['is_del']);
|
||||
}, function ($query) {
|
||||
$query->where('StoreGroupOrder.is_del', 0);
|
||||
});
|
||||
$count = $query->count();
|
||||
$list = $query->with(['orderList' => function (Relation $query) {
|
||||
$query->field('order_id,group_order_id,activity_type,pay_price')->with(['orderProduct','presellOrder']);
|
||||
}])->page($page, $limit)->order('create_time DESC')->select();
|
||||
$groupList = $query->with(['orderList' => function (Relation $query) {
|
||||
$query->field('order_id,group_order_id,activity_type,pay_price,status,mer_id')->with(['merchant' => function ($query) {
|
||||
$query->field('mer_id,mer_name,settle_cycle,interest_rate');
|
||||
}, 'orderProduct','presellOrder']);
|
||||
}, 'interest'])->page($page, $limit)->order('create_time DESC')->select();
|
||||
$list = [];
|
||||
foreach ($groupList as $k => $item) {
|
||||
$current = $item->toArray();
|
||||
if (!empty($item->interest)) {
|
||||
$interest = $item->interest->calculateInterest();
|
||||
$current['interest']['total_amount'] = bcadd($item->interest->total_price, $interest, 2);
|
||||
} else {
|
||||
$current['interest']['total_amount'] = $item['total_price'];
|
||||
}
|
||||
$list[] = $current;
|
||||
}
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
@ -81,13 +115,26 @@ class StoreGroupOrderRepository extends BaseRepository
|
||||
public function detail($uid, $id, $flag = true)
|
||||
{
|
||||
$where = $this->getAll ? ['uid' => $uid] : ['paid' => 0, 'uid' => $uid];
|
||||
return $this->search($where)->where('group_order_id', $id)->with(['orderList' => function (Relation $query) use ($flag) {
|
||||
$order = StoreGroupOrder::where($where)
|
||||
->where('group_order_id', $id)
|
||||
->where('is_del', 0)
|
||||
->with(['orderList' => function (Relation $query) use ($flag) {
|
||||
$query->when($flag, function ($query) {
|
||||
$query->field('order_id,group_order_id,mer_id,order_sn,activity_type,pay_price,order_extend,order_type,is_virtual');
|
||||
})->with(['merchant' => function ($query) use ($flag) {
|
||||
$flag && $query->field('mer_id,mer_name');
|
||||
$flag && $query->field('mer_id,mer_name,settle_cycle,interest_rate');
|
||||
}, 'orderProduct', 'presellOrder']);
|
||||
}])->find();
|
||||
}, 'interest'])
|
||||
->order('create_time DESC')->append(['cancel_time', 'cancel_unix'])->find();
|
||||
if (empty($order)) {
|
||||
throw new DataNotFoundException('订单不存在或已取消');
|
||||
}
|
||||
if (!empty($order->interest)) {
|
||||
$interest = $order->interest->calculateInterest();
|
||||
$order->interest->interest = $interest;
|
||||
$order->interest->total_amount = bcadd($order->interest->total_price, $interest, 2);
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
|
||||
public function status($uid, $id)
|
||||
@ -163,6 +210,10 @@ class StoreGroupOrderRepository extends BaseRepository
|
||||
'user_type' => $storeOrderStatusRepository::U_TYPE_SYSTEM,
|
||||
];
|
||||
}
|
||||
if (!empty($order->interest) && $order->interest->status == StoreOrderInterest::STATUS_UNSETTLED) {
|
||||
$order->interest->status = StoreOrderInterest::STATUS_DELETED;
|
||||
$order->interest->save();
|
||||
}
|
||||
$groupOrder->save();
|
||||
$storeOrderStatusRepository->batchCreateLog($orderStatus);
|
||||
});
|
||||
|
@ -3,6 +3,9 @@
|
||||
namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\dao\store\order\StoreCartDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\repositories\community\CommunityRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponUserRepository;
|
||||
use app\common\repositories\store\product\ProductAssistSkuRepository;
|
||||
@ -41,7 +44,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$addressRepository = app()->make(UserAddressRepository::class);
|
||||
$address = $addressRepository->getWhere(['uid' => $uid, 'address_id' => $addressId]);
|
||||
}
|
||||
|
||||
$storeCartRepository = app()->make(StoreCartRepository::class);
|
||||
$res = $storeCartRepository->checkCartList($storeCartRepository->cartIbByData($cartId, $uid, $address), 0, $user);
|
||||
$merchantCartList = $res['list'];
|
||||
@ -95,8 +97,29 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($order_type == 98 && count($merchantCartList) > 1) {
|
||||
throw new ValidateException('采购商品不支持跨店购买');
|
||||
}
|
||||
$community = [];
|
||||
if ($order_type == 98) {
|
||||
$sourceIdArray = [];
|
||||
foreach($merchantCart['list'] as $prod){
|
||||
if ($prod['source_id'] > 0) {
|
||||
$sourceIdArray[] = $prod['source_id'];
|
||||
}
|
||||
}
|
||||
if (count($sourceIdArray)) {
|
||||
if (count(array_unique($sourceIdArray)) > 1) {
|
||||
throw new ValidateException('转售商品数据异常');
|
||||
}
|
||||
$community = Db::name('Community')->where('community_id', $communityIdArray[0] ?? 0)->field('community_id, title, image')->fetchSql(false)->find();
|
||||
if ($community) {
|
||||
$deliverMethod = Db::name('resale')->where('community_id', $communityIdArray[0] ?? 0)->value('deliver_method');
|
||||
$deliverMethodArray = explode(',', $deliverMethod);
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($merchantCart, $cart);
|
||||
|
||||
$order_price = 0;
|
||||
$total_true_price = 0;
|
||||
$order_total_price = 0;
|
||||
@ -113,11 +136,13 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
app()->make(StoreDiscountRepository::class)
|
||||
->check($merchantCartList[0]['list'][0]['source_id'], $merchantCartList[0]['list'], $user);
|
||||
}
|
||||
|
||||
$orderDeliveryStatus = true;
|
||||
$order_svip_discount = 0;
|
||||
// 循环计算每个店铺的订单数据
|
||||
foreach ($merchantCartList as &$merchantCart) {
|
||||
if ($order_type == 98 && !empty($deliverMethodArray)) {
|
||||
$merchantCart['delivery_way'] = $deliverMethodArray;
|
||||
}
|
||||
$postageRule = [];
|
||||
$total_price = 0;
|
||||
$total_num = 0;
|
||||
@ -147,6 +172,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$product_cart = [];
|
||||
|
||||
foreach ($merchantCart['list'] as $k => $cart) {
|
||||
//处理转售送货方式
|
||||
if ($order_type == 98) {
|
||||
$merchantCart['list'][$k]['product']['delivery_way'] = $cart['product']['delivery_way'] = $deliverMethod ?? '';
|
||||
}
|
||||
//获取订单类型, 活动商品单次只能购买一个
|
||||
if ($cart['product']['delivery_way']) {
|
||||
$delivery_way = explode(',', $cart['product']['delivery_way']);
|
||||
@ -208,7 +237,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$use_svip = 0;
|
||||
//获取运费规则和统计商品数据
|
||||
foreach ($merchantCart['list'] as &$cart) {
|
||||
|
||||
if ($cart['product_type'] == 10 && $cart['productDiscountAttr']) {
|
||||
$cart['productAttr']['price'] = $cart['productDiscountAttr']['active_price'];
|
||||
$cart['productAttr']['show_svip_price'] = false;
|
||||
@ -218,8 +246,13 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
throw new ValidateException('购买商品数必须大于0');
|
||||
}
|
||||
$svip_discount = 0;
|
||||
|
||||
$price = bcmul($cart['cart_num'], $this->cartByPrice($cart), 2);
|
||||
$realPrice = $this->cartByPrice($cart);
|
||||
if ($cart['product_type'] == 98) {
|
||||
$cart['product']['price'] = $realPrice;
|
||||
$cart['productAttr']['price'] = $realPrice;
|
||||
$cart['productAttr']['stock'] = $cart['cart_num'];
|
||||
}
|
||||
$price = bcmul($cart['cart_num'], $realPrice, 2);
|
||||
$cart['total_price'] = $price;
|
||||
$cart['postage_price'] = 0;
|
||||
$cart['svip_discount'] = 0;
|
||||
@ -881,6 +914,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
'order_total_postage',
|
||||
'order_price',
|
||||
'total_price',
|
||||
'community',
|
||||
'platformCoupon',
|
||||
'enabledPlatformCoupon',
|
||||
'usePlatformCouponId',
|
||||
@ -912,7 +946,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
if ($orderInfo['order_price'] > 1000000) {
|
||||
throw new ValidateException('支付金额超出最大限制');
|
||||
}
|
||||
if ($orderInfo['status'] == 'noDeliver') throw new ValidateException('部分商品不支持该区域');
|
||||
if ($orderInfo['status'] == 'noDeliver') throw new ValidateException('商品不支持该区域');
|
||||
if ($orderInfo['status'] == 'noAddress') throw new ValidateException('请选择地址');
|
||||
if (!$order_model && $orderInfo['allow_address']) {
|
||||
if (!$orderInfo['address']) throw new ValidateException('请选择正确的收货地址');
|
||||
@ -924,7 +958,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$extend = [];
|
||||
}
|
||||
$orderType = $orderInfo['order_type'];
|
||||
if ($orderType && (count($orderInfo['order']) > 1 || ($orderType != 10 && count($orderInfo['order'][0]['list']) > 1))) {
|
||||
if ($orderType == 0 && $pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
|
||||
throw new ValidateException('该商品不支持先货后款');
|
||||
}
|
||||
if (!in_array($orderType, [0, 98]) && (count($orderInfo['order']) > 1 || ($orderType != 10 && count($orderInfo['order'][0]['list']) > 1))) {
|
||||
throw new ValidateException('活动商品请单独购买');
|
||||
}
|
||||
|
||||
@ -939,6 +976,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
//检查发票状态
|
||||
if (isset($receipt_data[$merchantCart['mer_id']]) && !$merchantCart['openReceipt'])
|
||||
throw new ValidateException('该店铺不支持开发票');
|
||||
if ($pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && !$merchantCart['credit_buy']) {
|
||||
throw new ValidateException("{$merchantCart['mer_name']}不支持先货后款");
|
||||
}
|
||||
|
||||
foreach ($merchantCart['list'] as $cart) {
|
||||
if (!$cartSpread && $cart['spread_id']) {
|
||||
@ -946,6 +986,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($orderType == 98 && count($merchantCartList) > 1) {
|
||||
throw new ValidateException('采购商品不支持跨店购买');
|
||||
}
|
||||
if ($hasTake) {
|
||||
app()->make(UserAddressValidate::class)->scene('take')->check($post);
|
||||
}
|
||||
@ -975,7 +1018,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$totalCost = 0;
|
||||
$cartIds = [];
|
||||
$orderList = [];
|
||||
|
||||
foreach ($merchantCartList as $k => $merchantCart) {
|
||||
$cost = 0;
|
||||
$total_extension_one = 0;
|
||||
@ -1058,7 +1100,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
} else if (isset($merchantCart['merchantCategory']['commission_rate']) && $merchantCart['merchantCategory']['commission_rate'] > 0) {
|
||||
$rate = bcmul($merchantCart['merchantCategory']['commission_rate'], 100, 4);
|
||||
}
|
||||
$user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['detail']) : '';
|
||||
$user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['village'] . $address['brigade'] . $address['detail']) : '';
|
||||
$user_address_code = isset($address) ? ($address['province_code'] . ',' . $address['city_code'] . ',' . $address['district_code'] . ',' . $address['street_code'] . ',' . $address['village_code'] . ',' . $address['brigade_id']) : '';
|
||||
//整理订单数据
|
||||
$_order = [
|
||||
'cartInfo' => $merchantCart,
|
||||
@ -1076,6 +1119,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
'real_name' => $merchantCart['order']['isTake'] ? $post['real_name'] : ($address['real_name'] ?? ''),
|
||||
'user_phone' => $merchantCart['order']['isTake'] ? $post['phone'] : ($address['phone'] ?? ''),
|
||||
'user_address' => $user_address,
|
||||
'user_address_code' => $user_address_code,
|
||||
'cart_id' => implode(',', array_column($merchantCart['list'], 'cart_id')),
|
||||
'total_num' => $merchantCart['order']['total_num'],
|
||||
'total_price' => $merchantCart['order']['total_price'],
|
||||
@ -1125,7 +1169,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$group = Db::transaction(function () use ($ex, $user, $topUid, $spreadUid, $uid, $receipt_data, $cartIds, $allUseCoupon, $groupOrder, $orderList, $orderInfo) {
|
||||
$storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
|
||||
$storeCartRepository = app()->make(StoreCartRepository::class);
|
||||
/** @var ProductAttrValueRepository $attrValueRepository */
|
||||
$attrValueRepository = app()->make(ProductAttrValueRepository::class);
|
||||
/** @var ProductRepository $productRepository */
|
||||
$productRepository = app()->make(ProductRepository::class);
|
||||
$storeOrderProductRepository = app()->make(StoreOrderProductRepository::class);
|
||||
$couponUserRepository = app()->make(StoreCouponUserRepository::class);
|
||||
@ -1158,9 +1204,20 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
app()->make(ProductGroupSkuRepository::class)->descStock($cart['activeSku']['product_group_id'], $cart['activeSku']['unique'], $cart['cart_num']);
|
||||
$productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']);
|
||||
$attrValueRepository->descStock($cart['product']['old_product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
|
||||
} else {
|
||||
if ($cart['source'] == StoreCartDao::SOURCE_COMMUNITY_RESALE) {
|
||||
/** @var CommunityRepository $communityRepository */
|
||||
$communityRepository = app()->make(CommunityRepository::class);
|
||||
$communityRepository->saleOrCancel($cart['source_id']);
|
||||
$attrValueRepository->incSales($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
|
||||
$productRepository->incSales($cart['product']['product_id'], $cart['cart_num']);
|
||||
} else {
|
||||
$attrValueRepository->descStock($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
|
||||
$productRepository->descStock($cart['product']['product_id'], $cart['cart_num']);
|
||||
}
|
||||
/** @var PurchaseRecordRepository $purchaseRecordRepo */
|
||||
$purchaseRecordRepo = app()->make(PurchaseRecordRepository::class);
|
||||
$purchaseRecordRepo->incSalesVolume($cart['product']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
|
||||
if ($cart['integral'] && $cart['integral']['use'] > 0) {
|
||||
$productRepository->incIntegral($cart['product']['product_id'], $cart['integral']['use'], $cart['integral']['price']);
|
||||
}
|
||||
@ -1212,6 +1269,9 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$orderProduct = [];
|
||||
$orderStatus = [];
|
||||
foreach ($orderList as $order) {
|
||||
if ($order['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
|
||||
$order['status'] = StoreOrder::STATUS_WAIT_CONFIRM;
|
||||
}
|
||||
$cartInfo = $order['cartInfo'];
|
||||
unset($order['cartInfo']);
|
||||
//创建子订单
|
||||
|
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\repositories\store\order;
|
||||
|
||||
use app\common\model\store\order\StoreOrderInterest;
|
||||
use app\common\repositories\BaseRepository;
|
||||
|
||||
class StoreOrderInterestRepository extends BaseRepository
|
||||
{
|
||||
|
||||
public function create($data)
|
||||
{
|
||||
$data['status'] = StoreOrderInterest::STATUS_UNSETTLED;
|
||||
$model = new StoreOrderInterest();
|
||||
return $model->save($data);
|
||||
}
|
||||
|
||||
public function getByGroupOrder($groupOrderId)
|
||||
{
|
||||
return StoreOrderInterest::where('group_order_id', $groupOrderId)->find();
|
||||
}
|
||||
|
||||
public function getByOrder($orderId)
|
||||
{
|
||||
return StoreOrderInterest::where('order_id', $orderId)->find();
|
||||
}
|
||||
|
||||
}
|
@ -14,6 +14,9 @@ namespace app\common\repositories\store\order;
|
||||
use app\common\dao\store\order\StoreOrderDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreOrderInterest;
|
||||
use app\common\model\store\order\StoreRefundOrder;
|
||||
use app\common\model\store\product\PurchaseRecord;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\delivery\DeliveryOrderRepository;
|
||||
@ -74,7 +77,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
/**
|
||||
* 支付类型
|
||||
*/
|
||||
const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr', 'scrcu'];
|
||||
const PAY_TYPE = ['balance', 'weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr', 'scrcu', 'creditBuy'];
|
||||
|
||||
const TYPE_SN_ORDER = 'wxo';
|
||||
const TYPE_SN_PRESELL = 'wxp';
|
||||
@ -268,6 +271,8 @@ class StoreOrderRepository extends BaseRepository
|
||||
$flag = false;
|
||||
}
|
||||
}
|
||||
//发起物流信息处理
|
||||
event('order.sendGoodsCode', $order);
|
||||
|
||||
// 商户流水账单数据
|
||||
$finance[] = [
|
||||
@ -459,7 +464,6 @@ class StoreOrderRepository extends BaseRepository
|
||||
});
|
||||
event('order.take', compact('order'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -475,7 +479,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
try {
|
||||
$this->batchPrinter($orderId, $merId);
|
||||
} catch (Exception $exception) {
|
||||
Log::info('自动打印小票报错:' . $exception);
|
||||
Log::info('自动打印小票报错');
|
||||
}
|
||||
} else {
|
||||
Log::info('自动打印小票验证:商户ID【' . $merId . '】,自动打印状态未开启');
|
||||
@ -522,6 +526,18 @@ class StoreOrderRepository extends BaseRepository
|
||||
return $cart['productAssistAttr']['assist_price'];
|
||||
} else if ($cart['product_type'] == '4') {
|
||||
return $cart['activeSku']['active_price'];
|
||||
// 更新调货价格
|
||||
} else if ($cart['product_type'] == '98') {
|
||||
if ($cart['source_id'] > 0) {
|
||||
$price = Db::name('resale')->where('community_id', $cart['source_id'])->where('product_attr_unique', $cart['product_attr_unique'])->where('status', 0)->value('price');
|
||||
if ($price) {
|
||||
return $price;
|
||||
} else {
|
||||
throw new ValidateException('转售商品数据异常');
|
||||
}
|
||||
} else {
|
||||
return $cart['productAttr']['price'];
|
||||
}
|
||||
} else {
|
||||
return $cart['productAttr']['price'];
|
||||
}
|
||||
@ -537,6 +553,14 @@ class StoreOrderRepository extends BaseRepository
|
||||
return 0;
|
||||
} else if ($cart['product_type'] == '4') {
|
||||
return 0;
|
||||
// 更新调货价格
|
||||
} else if ($cart['product_type'] == '98') {
|
||||
$price = Db::name('resale')->where('product_attr_unique', $cart['product_attr_unique'])->where('status', 0)->value('price');
|
||||
if ($price) {
|
||||
return $price;
|
||||
} else {
|
||||
return $cart['productAttr']['price'];
|
||||
}
|
||||
} else {
|
||||
return $cart['productAttr']['price'];
|
||||
}
|
||||
@ -560,16 +584,21 @@ class StoreOrderRepository extends BaseRepository
|
||||
*/
|
||||
public function userOrderNumber(int $uid, $product_type=0)
|
||||
{
|
||||
$noPay = app()->make(StoreGroupOrderRepository::class)->orderNumber($uid,$product_type);
|
||||
$noPostage = $this->dao->search(['uid' => $uid, 'status' => 0, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count();
|
||||
$all = $this->dao->search(['uid' => $uid, 'status' => -2,'is_user' => 1])->where('StoreOrder.is_del', 0)->count();
|
||||
$noDeliver = $this->dao->search(['uid' => $uid, 'status' => 1, 'paid' => 1])->where('StoreOrder.is_del', 0)->count();
|
||||
$noComment = $this->dao->search(['uid' => $uid, 'status' => 2, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count();
|
||||
$done = $this->dao->search(['uid' => $uid, 'status' => 3, 'paid' => 1,'is_user' => 1])->where('StoreOrder.is_del', 0)->count();
|
||||
$refund = app()->make(StoreRefundOrderRepository::class)->getWhereCount(['uid' => $uid, 'status' => [0, 1, 2]]);
|
||||
//$orderPrice = $this->dao->search(['uid' => $uid, 'paid' => 1])->sum('pay_price');
|
||||
$orderCount = $this->dao->search(['uid' => $uid, 'paid' => 1,'is_user' => 1])->count();
|
||||
return compact('noComment', 'done', 'refund', 'noDeliver', 'noPay', 'noPostage', 'orderCount', 'all');
|
||||
//activity_type:0普通订单 98 采购订单
|
||||
//$noPay = app()->make(StoreGroupOrderRepository::class)->orderNumber($uid, $product_type);
|
||||
$isUser = 1;
|
||||
if ($product_type == 98) {
|
||||
$isUser = 0;
|
||||
}
|
||||
$noPay = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where($this->getOrderType(1))->whereRaw("(StoreOrder.paid=0 and StoreOrder.pay_type!=8) or (StoreOrder.paid=1 and StoreOrder.pay_type=8 and StoreOrder.status=2)")->where('activity_type', $product_type)->where('StoreOrder.is_del', 0)->fetchSql(false)->count();
|
||||
$noPostage = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where($this->getOrderType(2))->where('activity_type', $product_type)->where('StoreOrder.is_del', 0)->fetchSql(false)->count();
|
||||
$noDeliver = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where($this->getOrderType(3))->where('activity_type', $product_type)->where('StoreOrder.is_del', 0)->fetchSql(false)->count();
|
||||
$noComment = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where($this->getOrderType(4))->where('activity_type', $product_type)->where('StoreOrder.is_del', 0)->fetchSql(false)->count();
|
||||
$done = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where($this->getOrderType(5))->where('activity_type', $product_type)->where('StoreOrder.is_del', 0)->fetchSql(false)->count();
|
||||
$refund = StoreRefundOrder::alias('t1')->join('store_order t2', 't1.order_id=t2.order_id')->where('t1.uid', $uid)->where('t1.status', 3)->where('t2.activity_type', $product_type)->count();
|
||||
$orderPrice = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where($this->getOrderType(8))->where('activity_type', $product_type)->where('StoreOrder.is_del', 0)->fetchSql(false)->sum('pay_price');
|
||||
$orderCount = $this->dao->search(['uid' => $uid, 'is_user' => $isUser])->where('activity_type', $product_type)->where('StoreOrder.is_del', 0)->fetchSql(false)->count();
|
||||
return compact('noComment', 'done', 'refund', 'noDeliver', 'noPay', 'noPostage', 'orderPrice', 'orderCount');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -614,6 +643,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
$order->presell_price = $order->pay_price;
|
||||
}
|
||||
}
|
||||
$order->order_status = $this->getOrderStatusV2($order);
|
||||
return $order;
|
||||
}
|
||||
|
||||
@ -723,10 +753,16 @@ class StoreOrderRepository extends BaseRepository
|
||||
public function takeAfter(StoreOrder $order, ?User $user)
|
||||
{
|
||||
Db::transaction(function () use ($user, $order) {
|
||||
if ($user) $this->computed($order, $user);
|
||||
if ($user && $order->pay_type != StoreGroupOrder::PAY_TYPE_CREDIT_BUY) $this->computed($order, $user);
|
||||
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_TAKE_SUCCESS', 'id' => $order->order_id]);
|
||||
Queue::push(SendSmsJob::class, ['tempId' => 'ADMIN_TAKE_DELIVERY_CODE', 'id' => $order->order_id]);
|
||||
if ($order->pay_type != StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
|
||||
app()->make(MerchantRepository::class)->computedLockMoney($order);
|
||||
}
|
||||
if (!empty($order->interest) && $order->interest->status == StoreOrderInterest::STATUS_UNSETTLED) {
|
||||
$order->interest->start_time = date('Y-m-d H:i:s', strtotime("+{$order->interest->settle_cycle} days"));
|
||||
$order->interest->save();
|
||||
}
|
||||
$order->save();
|
||||
});
|
||||
}
|
||||
@ -793,13 +829,13 @@ class StoreOrderRepository extends BaseRepository
|
||||
if ($orderType === 0) $where['order_type'] = 0; //普通订单
|
||||
if ($orderType === 1) $where['take_order'] = 1; //已核销订单
|
||||
if ($product_type!=0) $where['product_type'] = $product_type; //商品属性
|
||||
//1: 未支付 2: 未发货 3: 待收货 4: 待评价 5: 交易完成 6: 已退款 7: 已删除
|
||||
//1: 未支付 2: 未发货 3: 待收货 4: 待评价 5: 交易完成 6: 已退款 7: 已删除 8: 已支付
|
||||
$all = $this->dao->search($where, $sysDel)->where($this->getOrderType(0))->count();
|
||||
$statusAll = $all;
|
||||
$unpaid = $this->dao->search($where, $sysDel)->where($this->getOrderType(1))->count();
|
||||
$unpaid = $this->dao->search($where, $sysDel)->where($this->getOrderType(1))->whereRaw("StoreOrder.paid=0 or (StoreOrder.paid=1 and StoreOrder.pay_type=8 and StoreOrder.status=2)")->count();
|
||||
$unshipped = $this->dao->search($where, $sysDel)->where($this->getOrderType(2))->count();
|
||||
$untake = $this->dao->search($where, $sysDel)->where($this->getOrderType(3))->count();
|
||||
$unevaluate = $this->dao->search($where, $sysDel)->where($this->getOrderType(4))->count();
|
||||
$unevaluate = $this->dao->search($where, $sysDel)->where($this->getOrderType(4))->where('paid', 1)->where('pay_type', '<>', StoreGroupOrder::PAY_TYPE_CREDIT_BUY)->count();
|
||||
$complete = $this->dao->search($where, $sysDel)->where($this->getOrderType(5))->count();
|
||||
$refund = $this->dao->search($where, $sysDel)->where($this->getOrderType(6))->count();
|
||||
$del = $this->dao->search($where, $sysDel)->where($this->getOrderType(7))->count();
|
||||
@ -843,10 +879,10 @@ class StoreOrderRepository extends BaseRepository
|
||||
$param['StoreOrder.is_del'] = 0;
|
||||
switch ($status) {
|
||||
case 1:
|
||||
$param['paid'] = 0;
|
||||
// $param['StoreOrder.paid'] = 0;
|
||||
break; // 未支付
|
||||
case 2:
|
||||
$param['paid'] = 1;
|
||||
$param['StoreOrder.paid'] = 1;
|
||||
$param['StoreOrder.status'] = 0;
|
||||
break; // 待发货
|
||||
case 3:
|
||||
@ -863,11 +899,13 @@ class StoreOrderRepository extends BaseRepository
|
||||
break; // 已退款
|
||||
case 7:
|
||||
$param['StoreOrder.is_del'] = 1;
|
||||
break; // 待核销
|
||||
break; // 已删除
|
||||
break; // 待核销 已删除
|
||||
case 8:
|
||||
$param['StoreOrder.paid'] = 1;
|
||||
break; // 已支付
|
||||
default:
|
||||
unset($param['StoreOrder.is_del']);
|
||||
break; //全部
|
||||
break; // 全部
|
||||
}
|
||||
return $param;
|
||||
}
|
||||
@ -1486,6 +1524,12 @@ class StoreOrderRepository extends BaseRepository
|
||||
$status = $where['status'];
|
||||
unset($where['status']);
|
||||
$query = $this->dao->search($where)->where($this->getOrderType($status))
|
||||
->when($status == 4, function ($query) {
|
||||
$query->where('paid', 1)->where('pay_type', '<>', StoreGroupOrder::PAY_TYPE_CREDIT_BUY);
|
||||
})
|
||||
->when($status == 1, function ($query) {
|
||||
$query->whereRaw("StoreOrder.paid=0 or (StoreOrder.paid=1 and StoreOrder.pay_type=8 and StoreOrder.status=2)");
|
||||
})
|
||||
->with([
|
||||
'orderProduct',
|
||||
'merchant' => function ($query) {
|
||||
@ -1565,7 +1609,6 @@ class StoreOrderRepository extends BaseRepository
|
||||
]);
|
||||
$count = $query->count();
|
||||
$list = $query->page($page, $limit)->select()->append(['refund_extension_one', 'refund_extension_two']);
|
||||
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
@ -1664,13 +1707,21 @@ class StoreOrderRepository extends BaseRepository
|
||||
*/
|
||||
public function getList(array $where, $page, $limit)
|
||||
{
|
||||
$query = $this->dao->search($where)->where('StoreOrder.is_del', 0);
|
||||
$status = $where['status'] ?? '';
|
||||
unset($where['status']);
|
||||
// 未支付订单
|
||||
if ($status == 1) {
|
||||
$query = $this->dao->search($where)->where($this->getOrderType($status))->whereRaw("(StoreOrder.paid=0 and StoreOrder.pay_type!=8) or (StoreOrder.paid=1 and StoreOrder.pay_type=8 and StoreOrder.status=2)")->where('StoreOrder.is_del', 0);
|
||||
} else {
|
||||
$query = $this->dao->search($where)->where($this->getOrderType($status))->where('StoreOrder.is_del', 0);
|
||||
}
|
||||
|
||||
$count = $query->count();
|
||||
$list = $query->with([
|
||||
'orderProduct',
|
||||
'presellOrder',
|
||||
'merchant' => function ($query) {
|
||||
return $query->field('mer_id,mer_name');
|
||||
return $query->field('mer_id,mer_name,settle_cycle,interest_rate');
|
||||
},
|
||||
'community',
|
||||
'receipt' => function ($query) {
|
||||
@ -1687,11 +1738,48 @@ class StoreOrderRepository extends BaseRepository
|
||||
$order->presell_price = $order->pay_price;
|
||||
}
|
||||
}
|
||||
if ($order->pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && $order->interest) {
|
||||
$order->interest_start_time = $order->interest->start_time;
|
||||
$order->interest_status = $order->interest->status;
|
||||
if ($order->interest_status == StoreOrderInterest::STATUS_SETTLED) {
|
||||
$order->interest_money = $order->interest->interest;
|
||||
} else {
|
||||
$order->interest_money = $order->interest->calculateInterest();
|
||||
}
|
||||
}
|
||||
$order->takeOrderCount = count($order['takeOrderList']);
|
||||
unset($order['takeOrderList']);
|
||||
$order->order_status = $this->getOrderStatusV2($order);
|
||||
unset($order['takeOrderList'], $order->interest);
|
||||
}
|
||||
|
||||
return compact( 'count','list');
|
||||
return compact( 'count','list', 'where');
|
||||
}
|
||||
|
||||
public function getOrderStatusV2($order) {
|
||||
// 订单状态 1 未支付 2待发货 3待收货 4待评价 5交易完成 6已退款 7待核销
|
||||
$order->order_status = 0;
|
||||
if ($order->paid == 0) {
|
||||
$order->order_status = 1;
|
||||
}
|
||||
if ($order->paid == 1 && $order->status == 0) {
|
||||
$order->order_status = 2;
|
||||
}
|
||||
if ($order->status == 1) {
|
||||
$order->order_status = 3;
|
||||
}
|
||||
if ($order->status == 2) {
|
||||
$order->order_status = 4;
|
||||
}
|
||||
if ($order->status == 3) {
|
||||
$order->order_status = 5;
|
||||
}
|
||||
if ($order->status == -1) {
|
||||
$order->order_status = 6;
|
||||
}
|
||||
if ($order->paid == 1 && $order->status == 0 && $order->order_type == 1) {
|
||||
$order->order_status = 7;
|
||||
}
|
||||
return $order->order_status;
|
||||
}
|
||||
|
||||
public function userList($uid, $page, $limit)
|
||||
@ -1905,6 +1993,31 @@ class StoreOrderRepository extends BaseRepository
|
||||
return $urlCode;
|
||||
}
|
||||
|
||||
public function logisticsQrcode($orderId, $order_sn)
|
||||
{
|
||||
$siteUrl = systemConfig('site_url');
|
||||
$name = md5('logi' . $orderId . date('Ymd')) . '.jpg';
|
||||
$attachmentRepository = app()->make(AttachmentRepository::class);
|
||||
$imageInfo = $attachmentRepository->getWhere(['attachment_name' => $name]);
|
||||
|
||||
if (isset($imageInfo['attachment_src']) && strstr($imageInfo['attachment_src'], 'http') !== false && curl_file_exist($imageInfo['attachment_src']) === false) {
|
||||
$imageInfo->delete();
|
||||
$imageInfo = null;
|
||||
}
|
||||
if (!$imageInfo) {
|
||||
$imageInfo = app()->make(QrcodeService::class)->getQRCodePath($order_sn, $name);
|
||||
if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
|
||||
$imageInfo['dir'] = tidy_url($imageInfo['dir'], null, $siteUrl);
|
||||
$attachmentRepository->create(systemConfig('upload_type') ?: 1, -2, $orderId, [
|
||||
'attachment_category_id' => 99,
|
||||
'attachment_name' => $imageInfo['name'],
|
||||
'attachment_src' => $imageInfo['dir']
|
||||
]);
|
||||
$urlCode = $imageInfo['dir'];
|
||||
} else $urlCode = $imageInfo['attachment_src'];
|
||||
return $urlCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 根据商品ID获取订单数
|
||||
* @param int $productId
|
||||
@ -2417,4 +2530,202 @@ class StoreOrderRepository extends BaseRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单结算
|
||||
* @param $id
|
||||
* @param $payType
|
||||
* @param $user
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function settle($id, $payType, $user)
|
||||
{
|
||||
/** @var StoreGroupOrderRepository $groupOrderRepository */
|
||||
$groupOrderRepository = app()->make(StoreGroupOrderRepository::class);
|
||||
$groupOrderRepository->getAll = true;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$groupOrder = $groupOrderRepository->detail($user['uid'], $id, false);
|
||||
if (!$groupOrder) {
|
||||
throw new Exception('订单不存在或已支付');
|
||||
}
|
||||
$order = $groupOrder->orderList[0];
|
||||
if (!$groupOrder->interest || $groupOrder->interest->status != StoreOrderInterest::STATUS_UNSETTLED || $order->status != 2) {
|
||||
throw new Exception('订单无需结算');
|
||||
}
|
||||
$interest = $groupOrder->interest->calculateInterest();
|
||||
$payMoney = bcadd($groupOrder->interest->total_price, $interest, 2);
|
||||
$result = true;
|
||||
$type = array_search($payType, StoreOrderRepository::PAY_TYPE);
|
||||
if (in_array($payType, ['weixin', 'alipay'], true) && request()->isApp()) {
|
||||
$payType .= 'App';
|
||||
}
|
||||
$data = ['type' => $type, 'order_id' => $groupOrder->group_order_id, 'paid' => true];
|
||||
if ($payMoney > 0) {
|
||||
$groupOrder->pay_price = $payMoney;
|
||||
if (!in_array($payType, ['balance', 'scrcu'])) {
|
||||
if (systemConfig('open_wx_combine')) {
|
||||
$service = new CombinePayService($payType, $groupOrder->getCombinePayParams('order_settle'));
|
||||
} else {
|
||||
$service = new PayService($payType, $groupOrder->getPayParams($payType === 'alipay' ? request()->param('return_url') : '', 'order_settle'));
|
||||
}
|
||||
$result = $service->pay($user);
|
||||
$data = array_merge($data, $result, ['paid' => false]);
|
||||
} else {
|
||||
$payTool = PayTool::instance($payType);
|
||||
$result = $payTool->pay($groupOrder);
|
||||
}
|
||||
}
|
||||
$groupOrder->interest->interest = $interest;
|
||||
if ($result === true) {
|
||||
//写入用户账单
|
||||
/** @var UserBillRepository $userBillRepository */
|
||||
$userBillRepository = app()->make(UserBillRepository::class);
|
||||
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', [
|
||||
'link_id' => $groupOrder['group_order_id'],
|
||||
'status' => 1,
|
||||
'title' => '购买商品',
|
||||
'number' => $groupOrder['pay_price'],
|
||||
'mark' => '余额支付支付' . floatval($groupOrder['pay_price']) . '元购买商品',
|
||||
'balance' => $user->now_money
|
||||
]);
|
||||
|
||||
/** @var StoreOrderRepository $storeOrderRepo */
|
||||
$storeOrderRepo = app()->make(StoreOrderRepository::class);
|
||||
$storeOrderRepo->paySuccess($groupOrder);
|
||||
app()->make(MerchantRepository::class)->computedLockMoney($groupOrder->orderList[0]);
|
||||
$groupOrder->interest->status = StoreOrderInterest::STATUS_SETTLED;
|
||||
$groupOrder->interest->settle_time = date('Y-m-d H:i:s');
|
||||
|
||||
//订单结算之后,修改订单支付方式为真实的支付方式
|
||||
$groupOrder->pay_type = $type;
|
||||
$groupOrder->save();
|
||||
$order->pay_type = $type;
|
||||
$order->save();
|
||||
}
|
||||
$groupOrder->interest->save();
|
||||
Db::commit();
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认接单
|
||||
* @param $user
|
||||
* @param $id
|
||||
* @param $type
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function confirm($id, $type)
|
||||
{
|
||||
/** @var StoreGroupOrderRepository $groupOrderRepository */
|
||||
$groupOrderRepository = app()->make(StoreGroupOrderRepository::class);
|
||||
$groupOrderRepository->getAll = true;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$groupOrder = $groupOrderRepository->get($id);
|
||||
if ($groupOrder->pay_type != StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
|
||||
throw new Exception('订单类型错误');
|
||||
}
|
||||
$order = $groupOrder->orderList[0];
|
||||
if ($order->status != StoreOrder::STATUS_WAIT_CONFIRM) {
|
||||
throw new Exception('订单状态错误');
|
||||
}
|
||||
if ($type == 2) {
|
||||
$order->is_del = 1;
|
||||
$groupOrder->is_del = 1;
|
||||
if (!empty($order->interest) && $order->interest->status == StoreOrderInterest::STATUS_UNSETTLED) {
|
||||
$order->interest->status = StoreOrderInterest::STATUS_DELETED;
|
||||
$order->interest->save();
|
||||
}
|
||||
} else {
|
||||
$order->status = StoreOrder::STATUS_WAIT_PAY;
|
||||
$groupOrder->paid = 1;
|
||||
$groupOrder->pay_time = date('Y-m-d H:i:s');
|
||||
$order->paid = 1;
|
||||
$order->pay_time = date('Y-m-d H:i:s');
|
||||
}
|
||||
$groupOrder->save();
|
||||
$order->save();
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购订单列表
|
||||
* @param $uid
|
||||
* @param $keyword
|
||||
* @param $page
|
||||
* @param $limit
|
||||
* @return array
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function purchaseOrder($where, $keyword, $page, $limit)
|
||||
{
|
||||
$orders = StoreOrder::where($where)
|
||||
->where('activity_type', 98)
|
||||
->whereIn('status', [StoreOrder::STATUS_WAIT_COMMENT, StoreOrder::STATUS_FINISH])
|
||||
->where('is_system_del', 0)
|
||||
->when($keyword !== '', function ($query) use ($keyword) {
|
||||
$query->where('order_sn|user_phone', 'like', "%$keyword%");
|
||||
})
|
||||
->page($page, $limit)
|
||||
->order('order_id', 'desc')
|
||||
->select();
|
||||
$return = [];
|
||||
foreach ($orders as $order) {
|
||||
$products = $order->orderProduct;
|
||||
$currentOrder = $order->toArray();
|
||||
foreach ($products as $k => $product) {
|
||||
$purchaseRecord = PurchaseRecord::where(['order_id' => $product['order_id'], 'order_product_id' => $product['product_id'], 'order_unique' => $product['product_sku']])->field('id,number,sales_volume')->find();
|
||||
if (!empty($purchaseRecord)) {
|
||||
$currentOrder['orderProduct'][$k]['sales_volume'] = $purchaseRecord->sales_volume;
|
||||
$currentOrder['orderProduct'][$k]['purchase_record'] = $purchaseRecord->toArray();
|
||||
} else {
|
||||
$currentOrder['orderProduct'][$k]['sales_volume'] = 0;
|
||||
$currentOrder['orderProduct'][$k]['purchase_record'] = [];
|
||||
}
|
||||
}
|
||||
$return[] = $currentOrder;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $orderId
|
||||
* @param $orderSn
|
||||
* 更新扫描发货状态
|
||||
*/
|
||||
public function deliveryGoods($orderId, $orderSn, $logisticsCode='')
|
||||
{
|
||||
if ($logisticsCode) {
|
||||
$order = $this->dao->search([], null)->where('order_sn', $orderSn)->where('order_id', $orderId)->where('logistics_code', $logisticsCode)->where('StoreOrder.status', 1)->where('StoreOrder.is_del', 0)->find();
|
||||
} else {
|
||||
$order = $this->dao->search([], null)->where('order_sn', $orderSn)->where('order_id', $orderId)->where('StoreOrder.status', 0)->where('StoreOrder.is_del', 0)->find();
|
||||
}
|
||||
if (!$order)
|
||||
throw new ValidateException('订单不存在或编码code错误');
|
||||
if ($order['order_type'])
|
||||
throw new ValidateException('订单类型错误');
|
||||
|
||||
if ($logisticsCode) {
|
||||
$order->status = 2;
|
||||
$order->mark = '快递员已完成送货';
|
||||
} else {
|
||||
$order->status = 1;
|
||||
$order->mark = '快递员已扫描取件';
|
||||
event('product.delivery', compact('order'));
|
||||
}
|
||||
$order->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -444,7 +444,7 @@ class StoreOrderRepository extends BaseRepository
|
||||
try {
|
||||
$this->batchPrinter($orderId, $merId);
|
||||
} catch (Exception $exception) {
|
||||
Log::info('自动打印小票报错:' . $exception);
|
||||
Log::info('自动打印小票报错');
|
||||
}
|
||||
} else {
|
||||
Log::info('自动打印小票验证:商户ID【' . $merId . '】,自动打印状态未开启');
|
||||
|
@ -15,6 +15,7 @@ namespace app\common\repositories\store\order;
|
||||
|
||||
|
||||
use app\common\dao\store\order\StoreRefundOrderDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreRefundOrder;
|
||||
use app\common\model\system\merchant\FinancialRecord;
|
||||
@ -268,6 +269,9 @@ class StoreRefundOrderRepository extends BaseRepository
|
||||
*/
|
||||
public function refunds(StoreOrder $order, array $ids, $uid, array $data)
|
||||
{
|
||||
if ($order->pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && $order->status == 2) {
|
||||
throw new ValidateException('已收货的订单不支持退款');
|
||||
}
|
||||
$orderId = $order->order_id;
|
||||
$products = app()->make(StoreOrderProductRepository::class)->userRefundProducts($ids, $uid, $orderId);
|
||||
if (!$products || count($ids) != count($products))
|
||||
@ -331,6 +335,9 @@ class StoreRefundOrderRepository extends BaseRepository
|
||||
$data['integral'] = $totalIntegral;
|
||||
$data['platform_refund_price'] = $totalPlatformRefundPrice;
|
||||
$data['refund_postage'] = $totalPostage;
|
||||
if ($order['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
|
||||
$data['refund_price'] = 0;
|
||||
}
|
||||
|
||||
return Db::transaction(function () use ($refundProduct, $data, $products, $order, &$refund_order_id) {
|
||||
event('refund.creates.before', compact('data'));
|
||||
@ -394,6 +401,9 @@ class StoreRefundOrderRepository extends BaseRepository
|
||||
*/
|
||||
public function refund(StoreOrder $order, $productId, $num, $uid, array $data)
|
||||
{
|
||||
if ($order->pay_type == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && $order->status == 2) {
|
||||
throw new ValidateException('已收货的订单不支持退款');
|
||||
}
|
||||
$orderId = $order->order_id;
|
||||
//TODO 订单状态生成佣金
|
||||
$product = app()->make(StoreOrderProductRepository::class)->userRefundProducts([$productId], $uid, $orderId);
|
||||
@ -464,6 +474,9 @@ class StoreRefundOrderRepository extends BaseRepository
|
||||
$data['refund_num'] = $num;
|
||||
$data['extension_one'] = $total_extension_one;
|
||||
$data['extension_two'] = $total_extension_two;
|
||||
if ($order['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
|
||||
$data['refund_price'] = 0;
|
||||
}
|
||||
|
||||
return Db::transaction(function () use ($order, $data, $product, $productId, $num) {
|
||||
event('refund.create.before', compact('data'));
|
||||
@ -871,6 +884,8 @@ class StoreRefundOrderRepository extends BaseRepository
|
||||
} else {
|
||||
$storeOrderStatusRepository->createAdminLog($orderStatus);
|
||||
}
|
||||
// 通知物流退货
|
||||
event('refund.deliver', compact('id', 'refund'));
|
||||
event('refund.agree', compact('id', 'refund'));
|
||||
});
|
||||
}
|
||||
|
@ -13,14 +13,21 @@
|
||||
|
||||
namespace app\common\repositories\store\product;
|
||||
|
||||
use app\common\dao\store\order\StoreCartDao;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreOrderProduct;
|
||||
use app\common\model\store\product\ProductAttrValue;
|
||||
use app\common\model\store\product\ProductLabel;
|
||||
use app\common\model\store\product\PurchaseRecord;
|
||||
use app\common\model\store\product\Spu;
|
||||
use app\common\model\store\Resale;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\community\CommunityRepository;
|
||||
use app\common\repositories\store\coupon\StoreCouponRepository;
|
||||
use app\common\repositories\store\GuaranteeRepository;
|
||||
use app\common\repositories\store\GuaranteeTemplateRepository;
|
||||
use app\common\repositories\store\GuaranteeValueRepository;
|
||||
use app\common\repositories\store\order\PurchaseRecordRepository;
|
||||
use app\common\repositories\store\order\StoreCartRepository;
|
||||
use app\common\repositories\store\order\StoreOrderProductRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
@ -38,6 +45,7 @@ use crmeb\services\QrcodeService;
|
||||
use crmeb\services\RedisCacheService;
|
||||
use crmeb\services\SwooleTaskService;
|
||||
use FormBuilder\Factory\Elm;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
@ -61,7 +69,7 @@ class ProductRepository extends BaseRepository
|
||||
|
||||
protected $dao;
|
||||
const CREATE_PARAMS = [
|
||||
"image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "mer_cate_id", "unit_name", "sort" , "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free','param_temp_id','extend',
|
||||
"image", "slider_image", "store_name", "store_info", "keyword", "bar_code", "guarantee_template_id", "cate_id", "mer_cate_id", "unit_name", "sort" , "is_show", "is_good", 'is_gift_bag', 'integral_rate', "video_link", "temp_id", "content", "spec_type", "extension_type", "attr", 'mer_labels', 'delivery_way', 'delivery_free','param_temp_id','extend', 'source_product_id',
|
||||
["brand_id",0],
|
||||
['once_max_count',0],
|
||||
['once_min_count',0],
|
||||
@ -73,8 +81,8 @@ class ProductRepository extends BaseRepository
|
||||
['svip_price_type',0],
|
||||
['params',[]],
|
||||
];
|
||||
protected $admin_filed = 'Product.product_id,Product.mer_id,brand_id,spec_type,unit_name,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,U.rank,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,star,ficti,integral_total,integral_price_total,sys_labels,param_temp_id,mer_svip_status,svip_price,svip_price_type,update_time';
|
||||
protected $filed = 'Product.bar_code,Product.product_id,Product.mer_id,brand_id,unit_name,spec_type,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,integral_total,integral_price_total,mer_labels,Product.is_good,Product.is_del,type,param_temp_id,mer_svip_status,svip_price,svip_price_type,update_time';
|
||||
protected $admin_filed = 'Product.product_id,Product.mer_id,brand_id,spec_type,unit_name,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,U.rank,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,star,ficti,integral_total,integral_price_total,sys_labels,param_temp_id,mer_svip_status,svip_price,svip_price_type,update_time,source_product_id';
|
||||
protected $filed = 'Product.bar_code,Product.product_id,Product.mer_id,brand_id,unit_name,spec_type,mer_status,rate,reply_count,store_info,cate_id,Product.image,slider_image,Product.store_name,Product.keyword,Product.sort,Product.is_show,Product.sales,Product.price,extension_type,refusal,cost,ot_price,stock,is_gift_bag,Product.care_count,Product.status,is_used,Product.create_time,Product.product_type,old_product_id,integral_total,integral_price_total,mer_labels,Product.is_good,Product.is_del,type,param_temp_id,mer_svip_status,svip_price,svip_price_type,update_time,source_product_id';
|
||||
|
||||
const NOTIC_MSG = [
|
||||
1 => [
|
||||
@ -477,6 +485,7 @@ class ProductRepository extends BaseRepository
|
||||
'once_max_count' => $data['once_max_count'] ?? 0,
|
||||
'pay_limit' => $data['pay_limit'] ?? 0,
|
||||
'svip_price_type' => $data['svip_price_type'] ?? 0,
|
||||
'source_product_id' => $data['source_product_id'] ?? 0,
|
||||
];
|
||||
$result['bar_code'] = $data['attrValue'][0]['bar_code'] ?? '';
|
||||
if (isset($data['mer_id']))
|
||||
@ -866,7 +875,7 @@ class ProductRepository extends BaseRepository
|
||||
*/
|
||||
public function getList(?int $merId, array $where, int $page, int $limit)
|
||||
{
|
||||
$query = $this->dao->search($merId, $where)->with(['merCateId.category', 'storeCategory', 'brand']);
|
||||
$query = $this->dao->search($merId, $where)->with(['merCateId.category', 'storeCategory', 'brand', 'attrValue']);
|
||||
$count = $query->count();
|
||||
$data = $query->page($page, $limit)->setOption('field', [])->field($this->filed)->select();
|
||||
|
||||
@ -1605,14 +1614,14 @@ class ProductRepository extends BaseRepository
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($this->dao->updates($id,[$field => $status]) === false) {
|
||||
throw new \Exception('商品操作出错');
|
||||
throw new \Exception('商品操作出错', 500);
|
||||
}
|
||||
event('product.sell', ['product_id' => $productIds]);
|
||||
Db::commit();
|
||||
Queue::push(ChangeSpuStatusJob::class,['id' => $id,'product_type'=> $product_type]);
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new ValidateException($e->getMessage());
|
||||
throw new \Exception('商品操作出错', $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1753,6 +1762,7 @@ class ProductRepository extends BaseRepository
|
||||
{
|
||||
$productNum = $productNum ?? $cart['product_num'];
|
||||
Db::transaction(function () use ($order, $cart, $productNum) {
|
||||
/** @var ProductAttrValueRepository $productAttrValueRepository */
|
||||
$productAttrValueRepository = app()->make(ProductAttrValueRepository::class);
|
||||
if ($cart['product_type'] == '1') {
|
||||
$oldId = $cart['cart_info']['product']['old_product_id'];
|
||||
@ -1776,10 +1786,21 @@ class ProductRepository extends BaseRepository
|
||||
$oldId = $cart['cart_info']['product']['old_product_id'];
|
||||
$productAttrValueRepository->incSkuStock($oldId, $cart['cart_info']['productAttr']['sku'], $productNum);
|
||||
$this->dao->incStock($oldId, $productNum);
|
||||
} else {
|
||||
if ($cart['source'] == StoreCartDao::SOURCE_COMMUNITY_RESALE) {
|
||||
/** @var CommunityRepository $communityRepository */
|
||||
$communityRepository = app()->make(CommunityRepository::class);
|
||||
$communityRepository->saleOrCancel($cart['source_id'], 0);
|
||||
$productAttrValueRepository->descSales($cart['product_id'], $cart['cart_info']['productAttr']['unique'], $productNum);
|
||||
$this->dao->descSales($cart['product_id'], $productNum);
|
||||
} else {
|
||||
$productAttrValueRepository->incStock($cart['product_id'], $cart['cart_info']['productAttr']['unique'], $productNum);
|
||||
$this->dao->incStock($cart['product_id'], $productNum);
|
||||
}
|
||||
/** @var PurchaseRecordRepository $purchaseRecordRepo */
|
||||
$purchaseRecordRepo = app()->make(PurchaseRecordRepository::class);
|
||||
$purchaseRecordRepo->descSalesVolume($cart['product_id'], $cart['cart_info']['productAttr']['unique'], $productNum);
|
||||
}
|
||||
if ($cart->integral > 0) {
|
||||
$totalIntegral = bcmul($productNum, $cart->integral, 0);
|
||||
$this->dao->descIntegral($cart->product_id, $totalIntegral, bcmul(bcdiv($totalIntegral, $order->integral, 2), $order->integral_price, 2));
|
||||
@ -2243,6 +2264,9 @@ class ProductRepository extends BaseRepository
|
||||
];
|
||||
}
|
||||
}
|
||||
foreach ($data['attrValue'] as $k => $item) {
|
||||
$data['attrValue'][$k]['stock'] = 0;
|
||||
}
|
||||
app()->make(ProductLabelRepository::class)->checkHas($merId,$data['mer_labels']);
|
||||
$count = app()->make(StoreCategoryRepository::class)->getWhereCount(['store_category_id' => $data['cate_id'],'is_show' => 1]);
|
||||
if (!$count) throw new ValidateException('平台分类不存在或不可用');
|
||||
@ -2252,4 +2276,194 @@ class ProductRepository extends BaseRepository
|
||||
//单次限购
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购入库
|
||||
* @param $merId
|
||||
* @param $params
|
||||
* @return true
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function stockIn($merId, $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$supplierMerId = 0;
|
||||
if (empty($params['product_id']) && !empty($params['order_product_id'])) {
|
||||
//有商品无规格或者无商品无规格,导入商品和规格
|
||||
$product = $this->getWhere(['source_product_id' => $params['order_product_id'], 'mer_id' => $merId]);
|
||||
if (!empty($product)) {
|
||||
$unique = $this->importAttrValue($params['order_product_id'], $product->toArray(), $params['order_unique']);
|
||||
if (!$unique) {
|
||||
throw new \Exception('商品规格导入出错', 500);
|
||||
}
|
||||
} else {
|
||||
$productId = $this->import($params['order_product_id'], request()->userInfo());
|
||||
$product = $this->get($productId);
|
||||
}
|
||||
$sku = ProductAttrValue::where('product_id', $params['order_product_id'])->where('unique', $params['order_unique'])->value('sku');
|
||||
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $product['product_id'])->where('sku', $sku)->find();
|
||||
} else {
|
||||
//有商品有规格
|
||||
$product = $this->get($params['product_id']);
|
||||
$attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $params['product_id'])->where('unique', $params['unique'])->find();
|
||||
}
|
||||
if (!$product || !$attrValue) {
|
||||
throw new DataNotFoundException('商品或规格不存在');
|
||||
}
|
||||
$stockIn = $params['number'] ?? 0;
|
||||
$price = $params['price'] ?? 0;
|
||||
if (!empty($params['order_id'])) {
|
||||
//采购订单导入
|
||||
$orderMerId = StoreOrder::where('order_id', $params['order_id'])->value('mer_id');
|
||||
$orderProduct = StoreOrderProduct::where('order_id', $params['order_id'])->where('product_id', $params['order_product_id'])->where('product_sku', $params['order_unique'])->find();
|
||||
if (empty($orderProduct) || $orderProduct->is_imported == 1) {
|
||||
throw new ValidateException('订单商品不存在或已入库');
|
||||
}
|
||||
$stockIn = $orderProduct['product_num'] ?? 0;
|
||||
$price = $orderProduct['product_price'] ?? 0;
|
||||
$supplierMerId = $orderMerId ?? 0;
|
||||
}
|
||||
if ($stockIn <= 0) {
|
||||
throw new ValidateException('入库数量不能小于等于0');
|
||||
}
|
||||
$attrValue->stock = $attrValue->stock + $stockIn;
|
||||
$attrValue->save();
|
||||
$product->stock = $stockIn + $product->stock;
|
||||
if (!$product->save()) {
|
||||
throw new \Exception('商品库存保存失败', 500);
|
||||
}
|
||||
$model = new PurchaseRecord();
|
||||
$data = [
|
||||
'order_id' => $params['order_id'] ?? 0,
|
||||
'order_product_id' => $params['order_product_id'] ?? 0,
|
||||
'product_id' => $product->product_id,
|
||||
'number' => $stockIn,
|
||||
'order_unique' => $params['order_unique'] ?? '',
|
||||
'unique' => $attrValue['unique'],
|
||||
'price' => $price,
|
||||
'mer_id' => $product->mer_id,
|
||||
'supplier_mer_id' => $supplierMerId,
|
||||
];
|
||||
if (!$model->save($data)) {
|
||||
throw new \Exception('入库失败', 500);
|
||||
}
|
||||
if (isset($orderProduct) && !$orderProduct->save(['is_imported' => 1])) {
|
||||
throw new \Exception('订单商品更新出错', 500);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw new \Exception($e->getMessage(), $e->getCode());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入商品
|
||||
* @param $product_id
|
||||
* @param $user
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function import($product_id, $user)
|
||||
{
|
||||
$mer_id = Db::name('store_service')->where('uid', $user['uid'])->where('status', 1)->value('mer_id');
|
||||
if ($mer_id == 0) {
|
||||
throw new DataNotFoundException('商户不存在');
|
||||
}
|
||||
$find = Db::name('store_product')->where('product_id', $product_id)->find();
|
||||
if ($find) {
|
||||
if (!in_array($find['product_type'], [0, 98])) {
|
||||
throw new ValidateException('该商品不是普通商品');
|
||||
}
|
||||
$exist = Db::name('store_product')->where('source_product_id', $product_id)->where('mer_id', $mer_id)->find();
|
||||
if ($exist) {
|
||||
throw new ValidateException('已经导入过该商品了');
|
||||
}
|
||||
$attr = Db::name('store_product_attr')->where('product_id', $find['product_id'])->field('attr_name,attr_values,type')->select();
|
||||
foreach ($attr as $item) {
|
||||
$find['attr'][] = ['attr_name' => $item['attr_name'], 'detail' => explode('-!-', $item['attr_values'])];
|
||||
}
|
||||
$find['attrValue'] = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']])->field('image,price,cost,ot_price,svip_price,0 as stock,bar_code,weight,volume,detail')->select()->each(function ($item) {
|
||||
$item['detail'] = empty($item['detail']) ? [] : json_decode($item['detail'], true);
|
||||
return $item;
|
||||
})->toArray();
|
||||
$find['content'] = Db::name('store_product_content')->where('product_id', $find['product_id'])->value('content');
|
||||
$find['is_show'] = 0;
|
||||
$find['mer_id'] = $mer_id;
|
||||
$find['temp_id'] = "";
|
||||
$find['give_coupon_ids'] = [];
|
||||
$find['params'] = [];
|
||||
$find['extend'] = [];
|
||||
$find['param_temp_id'] = [];
|
||||
$find['mer_labels'] = [];
|
||||
$find['delivery_way'] = [0 => "2"];
|
||||
$find["guarantee_template_id"] = "";
|
||||
$find['product_type'] = 0;
|
||||
$find['mer_cate_id'] = [0 => 0];
|
||||
$find['is_used'] = 1;
|
||||
$find['status'] = 1;
|
||||
$find['mer_status'] = 1;
|
||||
$find['source_product_id'] = $product_id;
|
||||
$find['slider_image'] = explode(',', $find['slider_image']);
|
||||
unset($find['product_id'], $find['create_time']);
|
||||
}
|
||||
return $this->create($find, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅导入规格值
|
||||
* @param $oldProductId
|
||||
* @param $product
|
||||
* @param $unique
|
||||
* @return bool
|
||||
*/
|
||||
public function importAttrValue($oldProductId, $product, $unique)
|
||||
{
|
||||
$product['attrValue'] = ProductAttrValue::where(['product_id' => $oldProductId])->field('image,price,cost,ot_price,svip_price,0 as stock,bar_code,weight,volume,detail')->select();
|
||||
$settleParams = $this->setAttrValue($product, $product['product_id'], 0, 0, $product['mer_id']);
|
||||
if (!empty($settleParams['attrValue'])) {
|
||||
foreach ($settleParams['attrValue'] as $item) {
|
||||
if (!ProductAttrValue::getInstance()->insert($item)) {
|
||||
throw new ValidateException('商品规格保存出错');
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 可转售商品列表
|
||||
* @param
|
||||
* @param
|
||||
* @param
|
||||
* @return array
|
||||
*/
|
||||
public function communityProduct($where, $keyword, $page, $limit)
|
||||
{
|
||||
$merId = Db::name('store_service')->where('uid', $where['uid'])->where('status', 1)->value('mer_id', 0);
|
||||
unset($where['uid']);
|
||||
$where['status'] = 1;
|
||||
$where['is_show'] = 1;
|
||||
if (!empty($keyword)) {
|
||||
$where['keyword'] = $keyword;
|
||||
}
|
||||
$query = $this->dao->search($merId, $where)->with(['merCateId.category', 'storeCategory', 'brand', 'attrValue']);
|
||||
$count = $query->count();
|
||||
$data = $query->page($page, $limit)->setOption('field', [])->field($this->filed)->select();
|
||||
$data->append(['us_status']);
|
||||
$list = hasMany(
|
||||
$data ,
|
||||
'mer_labels',
|
||||
ProductLabel::class,
|
||||
'product_label_id',
|
||||
'mer_labels',
|
||||
['status' => 1],
|
||||
'product_label_id,product_label_id id,label_name name'
|
||||
);
|
||||
return compact('count', 'list');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -150,6 +150,7 @@ class SpuRepository extends BaseRepository
|
||||
$query->field($this->merchantFiled)->with(['type_name']);
|
||||
},
|
||||
'issetCoupon',
|
||||
'product.attrValue',
|
||||
]);
|
||||
$productMake = app()->make(ProductRepository::class);
|
||||
$count = $query->count();
|
||||
|
@ -35,6 +35,8 @@ class RelevanceRepository extends BaseRepository
|
||||
const TYPE_COMMUNITY_REPLY_START = 'community_reply_start';
|
||||
//商户权限
|
||||
const TYPE_MERCHANT_AUTH = 'mer_auth';
|
||||
//转售商品
|
||||
const TYPE_COMMUNITY_RESALE = 'community_resale'; //转售贴关联
|
||||
|
||||
//指定范围类型
|
||||
//0全部商品
|
||||
|
@ -465,6 +465,7 @@ class FinancialRecordRepository extends BaseRepository
|
||||
$date = ($type == 1) ? date('Y-m-d', $date_) : date('Y-m', $date_);
|
||||
$income = $this->countIncome($type, $where, $date,$merchant);
|
||||
$expend = $this->countExpend($type, $where, $date,$merchant);
|
||||
$data['e'] = $expend;
|
||||
$charge = bcsub($income['number'], $expend['number'], 2);
|
||||
|
||||
$data['date'] = $date;
|
||||
@ -634,7 +635,7 @@ class FinancialRecordRepository extends BaseRepository
|
||||
$financialType = ['brokerage_one', 'brokerage_two'];
|
||||
[$data['count_brokerage'], $data['number_brokerage']] = $this->dao->getDataByType($type, $where, $date, $financialType);
|
||||
|
||||
// 退回 手续费
|
||||
// 退回手续费
|
||||
$financialType = ['refund_charge'];
|
||||
[$data['count_charge'], $data['number_charge']] = $this->dao->getDataByType($type, $where, $date, $financialType);
|
||||
|
||||
@ -665,7 +666,7 @@ class FinancialRecordRepository extends BaseRepository
|
||||
$commission=['commission_to_town','commission_to_village','commission_to_service_team','commission_to_cloud_warehouse','commission_to_entry_merchant'];
|
||||
}
|
||||
if ($where['is_mer']) { //商户的
|
||||
//退回 收入
|
||||
//退回收入
|
||||
$financialType = ['refund_order'];
|
||||
[$data['count_refund'], $data['number_refund']] = $this->dao->getDataByType($type, $where, $date, $financialType);
|
||||
|
||||
|
@ -16,7 +16,9 @@ namespace app\common\repositories\system\merchant;
|
||||
|
||||
use app\common\dao\system\merchant\MerchantDao;
|
||||
use app\common\dao\system\serve\ServeOrderDao;
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use app\common\model\store\order\StoreOrderInterest;
|
||||
use app\common\model\store\product\ProductReply;
|
||||
use app\common\model\store\service\StoreService;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
@ -289,7 +291,7 @@ class MerchantRepository extends BaseRepository
|
||||
*/
|
||||
public function getList($where, $page, $limit, $userInfo)
|
||||
{
|
||||
$field = 'care_count,is_trader,type_id,mer_id,mer_banner,mini_banner,mer_name, mark,mer_avatar,product_score,service_score,postage_score,sales,status,is_best,create_time,long,lat,is_margin,service_phone,mer_address,mer_info';
|
||||
$field = 'care_count,is_trader,type_id,mer_id,mer_banner,mini_banner,mer_name, mark,mer_avatar,product_score,service_score,postage_score,sales,status,is_best,create_time,long,lat,is_margin,service_phone,mer_address,mer_info,credit_buy,settle_cycle,interest_rate';
|
||||
$where['status'] = 1;
|
||||
$where['mer_state'] = 1;
|
||||
$where['is_del'] = 0;
|
||||
@ -500,7 +502,8 @@ class MerchantRepository extends BaseRepository
|
||||
public function addLockMoney(int $merId, string $orderType, int $orderId, float $money)
|
||||
{
|
||||
if ($money <= 0) return;
|
||||
if (systemConfig('mer_lock_time')) {
|
||||
$payType = StoreOrder::getInstance()->where('order_id', $orderId)->value('pay_type');
|
||||
if (systemConfig('mer_lock_time') || $payType == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
|
||||
app()->make(UserBillRepository::class)->incBill($merId, 'mer_lock_money', $orderType, [
|
||||
'link_id' => ($orderType === 'order' ? 1 : 2) . $orderId,
|
||||
'mer_id' => $merId,
|
||||
@ -729,17 +732,16 @@ class MerchantRepository extends BaseRepository
|
||||
$values['order_sn'] = app()->make(StoreOrderRepository::class)->getNewOrderId('cs');
|
||||
$values['pay_time'] = date('y_m-d H:i:s', time());
|
||||
if (!app()->make(ServeOrderDao::class)->create($values)) {
|
||||
throw new \Exception('serve_order 保存出错');
|
||||
throw new \Exception('serve_order 保存出错', 500);
|
||||
}
|
||||
$merchant->paid_margin = bcadd($margin, $merchant->paid_margin, 2);
|
||||
$merchant->ot_margin = $merchant->paid_margin;
|
||||
$merchant->is_margin = MerchantRepository::PaidMargin;
|
||||
if ($merchant->save() === false) {
|
||||
throw new \Exception('merchant 保存出错');
|
||||
throw new \Exception('merchant 保存出错', 500);
|
||||
}
|
||||
|
||||
return [$income, $finance, true];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,17 @@ class UserAddressRepository extends BaseRepository
|
||||
return $this->dao->userFieldExists($this->dao->getPk(),$id,$uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $uid
|
||||
* @return bool
|
||||
* @author Qinii
|
||||
*/
|
||||
public function villageExists($field, $value)
|
||||
{
|
||||
return $this->dao->villageExists($field, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @return bool
|
||||
@ -115,6 +126,6 @@ class UserAddressRepository extends BaseRepository
|
||||
*/
|
||||
public function get($id,$uid)
|
||||
{
|
||||
return $this->dao->getWhere(['address_id' => $id,'uid' => $uid])->append(['area']);
|
||||
return $this->dao->getWhere(['address_id' => $id,'uid' => $uid]);
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ class UserRelationRepository extends BaseRepository
|
||||
];
|
||||
if($where['type'] == 10) $with = [
|
||||
'merchant' => function($query){
|
||||
$query->where('status',1)->where('mer_state',1)->where('is_del',0)->field('mer_id,type_id,mer_name,mer_avatar,sales,mer_info,care_count,status,is_del,mer_state');
|
||||
$query->field('mer_id,type_id,mer_name,mer_avatar,sales,mer_info,care_count,status,is_del,mer_state');
|
||||
}
|
||||
];
|
||||
$query = $this->dao->search($where);
|
||||
@ -181,15 +181,11 @@ class UserRelationRepository extends BaseRepository
|
||||
{
|
||||
if ($type == 10) {
|
||||
app()->make(MerchantRepository::class)->decCareCount($ids);
|
||||
$type_id = $ids;
|
||||
} else {
|
||||
foreach ($ids as $id) {
|
||||
$spu = $this->getSpu(['type_id' => $id, 'type' => $type]);
|
||||
$type_id[] = $spu->spu_id;
|
||||
}
|
||||
$type = 1;
|
||||
app()->make(ProductRepository::class)->decCareCount($ids);
|
||||
}
|
||||
$type_id = $ids;
|
||||
return $this->dao->search(['uid' => $uid,'type' => $type])->where('type_id','in',$type_id)->delete();
|
||||
}
|
||||
|
||||
|
253
app/common/service/JgPush.php
Normal file
253
app/common/service/JgPush.php
Normal file
@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\store\order\StoreGroupOrderRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use JPush\Client;
|
||||
use think\facade\Log;
|
||||
|
||||
class JgPush
|
||||
{
|
||||
|
||||
public $client;
|
||||
public $push;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->client = new Client('b5f679f4357018605ea6fd2e', 'c4fb573758f8d7058d697c54');
|
||||
$this->push = $this->client->push();
|
||||
$this->setPlatform();
|
||||
}
|
||||
|
||||
public function send($type, $data)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'ADMIN_PAY_SUCCESS_CODE':
|
||||
$groupOrder = app()->make(StoreGroupOrderRepository::class)->get($data['id']);
|
||||
if ($groupOrder) {
|
||||
foreach ($groupOrder->orderList as $order) {
|
||||
$this->client = new Client('b5f679f4357018605ea6fd2e', 'c4fb573758f8d7058d697c54');
|
||||
$this->push = $this->client->push();
|
||||
$this->setPlatform();
|
||||
$route = "/pages/admin/orderDetail/index?id={$order['order_id']}&mer_id={$order['mer_id']}";
|
||||
$merUserId = Merchant::where('mer_id', $order->mer_id)->value('uid');
|
||||
$jgRegisterId = User::where('uid', $merUserId)->value('jg_register_id');
|
||||
if (empty($jgRegisterId)) {
|
||||
continue;
|
||||
}
|
||||
$msg = $order['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY ? '您有新的订单已结算,请注意查看。' : '您有新的订单,请注意查看。';
|
||||
$msgType = $order['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY ? 'ORDER_SETTLEMENT' : 'ORDER_CREATE';
|
||||
$this->addRegistrationId($jgRegisterId);
|
||||
$this->androidNotification($msg, ['extras' => ['route' => $route, 'type' => $msgType]]);
|
||||
$this->iosNotification($msg, ['extras' => ['route' => $route, 'type' => $msgType]]);
|
||||
$this->push->send();
|
||||
unset($this->client, $this->push);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'DELIVER_GOODS_CODE':
|
||||
case 'ORDER_DELIVER_SUCCESS':
|
||||
$order = app()->make(StoreOrderRepository::class)->get($data['id']);
|
||||
if ($order) {
|
||||
$route = "/pages/order_details/index?order_id={$order['order_id']}";
|
||||
$jgRegisterId = User::where('uid', $order['uid'])->value('jg_register_id');
|
||||
if (!empty($jgRegisterId)) {
|
||||
$this->addRegistrationId($jgRegisterId);
|
||||
$this->androidNotification('您的订单已发货,请注意查看。', ['extras' => ['route' => $route]]);
|
||||
$this->iosNotification('您的订单已发货,请注意查看。', ['extras' => ['route' => $route]]);
|
||||
$this->push->send();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'MERCHANT_CREDIT_BUY_NOTICE':
|
||||
$route = "/pages/order_details/stay?order_id={$data['orderId']}&product_type=98";
|
||||
$merUserId = Merchant::where('mer_id', $data['id'])->value('uid');
|
||||
$jgRegisterId = User::where('uid', $merUserId)->value('jg_register_id');
|
||||
if (empty($jgRegisterId)) {
|
||||
break;
|
||||
}
|
||||
$this->addRegistrationId($jgRegisterId);
|
||||
$this->androidNotification('您的先货后款订单即将逾期,请尽快处理!', ['extras' => ['route' => $route]]);
|
||||
$this->iosNotification('您的先货后款订单即将逾期,请尽快处理!', ['extras' => ['route' => $route]]);
|
||||
$this->push->send();
|
||||
break;
|
||||
case 'ORDER_CREATE':
|
||||
$order = app()->make(StoreOrderRepository::class)->get($data['id']);
|
||||
if ($order->pay_type != StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
|
||||
break;
|
||||
}
|
||||
$route = "/pages/admin/orderDetail/index?id={$order['order_id']}&mer_id={$order['mer_id']}";
|
||||
$merUserId = Merchant::where('mer_id', $order['mer_id'])->value('uid');
|
||||
$jgRegisterId = User::where('uid', $merUserId)->value('jg_register_id');
|
||||
if (empty($jgRegisterId)) {
|
||||
break;
|
||||
}
|
||||
$this->addRegistrationId($jgRegisterId);
|
||||
$this->androidNotification('您有新的订单,请注意查看。', ['extras' => ['route' => $route, 'type' =>'ORDER_CREATE']]);
|
||||
$this->iosNotification('您有新的订单,请注意查看。', ['extras' => ['route' => $route, 'type' =>'ORDER_CREATE']]);
|
||||
$this->push->send();
|
||||
break;
|
||||
case 'ORDER_PAY_SUCCESS':
|
||||
$order = app()->make(StoreOrderRepository::class)->get($data['id']);
|
||||
if ($order->pay_type != StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
|
||||
break;
|
||||
}
|
||||
$route = "/pages/admin/orderDetail/index?id={$order['order_id']}&mer_id={$order['mer_id']}";
|
||||
$merUserId = Merchant::where('mer_id', $order['mer_id'])->value('uid');
|
||||
$jgRegisterId = User::where('uid', $merUserId)->value('jg_register_id');
|
||||
if (empty($jgRegisterId)) {
|
||||
break;
|
||||
}
|
||||
$this->addRegistrationId($jgRegisterId);
|
||||
$this->androidNotification('您有新的订单,请注意查看。', ['extras' => ['route' => $route, 'type' =>'ORDER_PAY_SUCCESS']]);
|
||||
$this->iosNotification('您有新的订单,请注意查看。', ['extras' => ['route' => $route, 'type' =>'ORDER_PAY_SUCCESS']]);
|
||||
$this->push->send();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置推送平台
|
||||
* @param array $platform
|
||||
*/
|
||||
public function setPlatform(array $platform = ['android', 'ios'])
|
||||
{
|
||||
$this->push->setPlatform($platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置推送设备
|
||||
* @param $registrationId
|
||||
* @return void
|
||||
*/
|
||||
public function addRegistrationId($registrationId)
|
||||
{
|
||||
$this->push->addRegistrationId($registrationId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给所有平台推送相同的 alert 消息
|
||||
* @param $alert
|
||||
* @return void
|
||||
*/
|
||||
public function setNotificationAlert($alert)
|
||||
{
|
||||
$this->push->setNotificationAlert($alert);
|
||||
}
|
||||
|
||||
/**
|
||||
* ios平台通知
|
||||
* @param $alert
|
||||
* @param $extras
|
||||
* @return void
|
||||
* @example $extras = ['sound' => 'sound', 'badge' => '+1', 'extras' => ['key' => 'value']
|
||||
*/
|
||||
public function iosNotification($alert, $extras = [])
|
||||
{
|
||||
$this->push->iosNotification($alert, $extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* android平台通知
|
||||
* @param $alert
|
||||
* @param $extras
|
||||
* @return void
|
||||
* @example $extras = ['alert' => 'alert', 'title' => 'title', 'extras' => ['key' => 'value']
|
||||
*/
|
||||
public function androidNotification($alert, $extras = [])
|
||||
{
|
||||
$this->push->androidNotification($alert, $extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* iOS VOIP 功能
|
||||
* @param $extras
|
||||
* @return void
|
||||
* @example $extras = ['key' => 'value'] //任意自定义 key/value 对,会透传给 APP
|
||||
*/
|
||||
public function voip($extras = [])
|
||||
{
|
||||
$this->push->voip($extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $msg_content
|
||||
* @param array $extras
|
||||
* @return void
|
||||
* @example $extras = ['title' => 'title', 'content_type' => 'text', 'extras' => ['key' => 'value']
|
||||
*/
|
||||
public function message($msg_content, array $extras = [])
|
||||
{
|
||||
$this->push->message($msg_content, $extras);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送可选项
|
||||
* @param array $options
|
||||
* @return void
|
||||
* @example $options = ['sendno' => 100, 'time_to_live' => 1, 'apns_production' => false, 'big_push_duration' => 1]
|
||||
* sendno: 表示推送序号,纯粹用来作为 API 调用标识,
|
||||
* time_to_live: 表示离线消息保留时长(秒),
|
||||
* apns_production: 表示APNs是否生产环境,
|
||||
* big_push_duration: 表示定速推送时长(分钟),又名缓慢推送
|
||||
*/
|
||||
public function options(array $options = [])
|
||||
{
|
||||
$this->push->options($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信通知
|
||||
* @param int $delay 延迟时间,单位秒
|
||||
* @param string $templateId 模板id
|
||||
* @param array $param 模板参数
|
||||
* @return void
|
||||
*/
|
||||
public function setSms(int $delay, string $templateId, array $param = [])
|
||||
{
|
||||
$this->push->setSms($delay, $templateId, $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备标签
|
||||
* @param $tag
|
||||
*/
|
||||
public function addTag($tag)
|
||||
{
|
||||
$this->push->addTag($tag);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设备标签AND
|
||||
* @param $tag
|
||||
*/
|
||||
public function addTagAnd($tag)
|
||||
{
|
||||
$this->push->addTagAnd($tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备别名
|
||||
* @param $alias
|
||||
*/
|
||||
public function addAlias($alias)
|
||||
{
|
||||
$this->push->addAlias($alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有用户
|
||||
*/
|
||||
public function addAllAudience()
|
||||
{
|
||||
$this->push->addAllAudience();
|
||||
}
|
||||
|
||||
}
|
@ -53,6 +53,20 @@ class Community extends BaseController
|
||||
return app('json')->success($this->repository->getList($where, $page, $limit));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @author Qinii
|
||||
*/
|
||||
public function resale()
|
||||
{
|
||||
$where = $this->request->params(['keyword','status','username','category_id','topic_id','is_show','is_type','resale_type']);
|
||||
$where['is_type'] = '3';
|
||||
$where['order'] = 'start';
|
||||
$where['is_del'] = 0;
|
||||
[$page, $limit] = $this->getPage();
|
||||
return app('json')->success($this->repository->getList($where, $page, $limit));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
@ -100,20 +114,21 @@ class Community extends BaseController
|
||||
|
||||
public function switchStatus($id)
|
||||
{
|
||||
$data = $this->request->params(['status', 'refusal']);
|
||||
$data = $this->request->params(['status', 'refusal', 'float_rate']);
|
||||
|
||||
if (!in_array($data['status'],[0,1,-1,-2]))
|
||||
return app('json')->fail('状态类型错误');
|
||||
|
||||
$data['is_show'] = ($data['status'] == 1) ? : 0;
|
||||
|
||||
$floatRate = $data['float_rate'] ?? 0;
|
||||
if($floatRate < 0 || $floatRate > 100)
|
||||
return app('json')->fail('浮动百分比错误');
|
||||
if($data['status'] == -1 && empty($data['refusal']))
|
||||
return app('json')->fail('请填写拒绝理由');
|
||||
if($data['status'] == -2 && empty($data['refusal']))
|
||||
return app('json')->fail('请填写下架原因');
|
||||
if (!$this->repository->exists($id))
|
||||
return app('json')->fail('数据不存在');
|
||||
|
||||
$this->repository->setStatus($id,$data);
|
||||
return app('json')->success('操作成功');
|
||||
}
|
||||
|
@ -99,6 +99,12 @@ class Merchant extends BaseController
|
||||
public function create(MerchantValidate $validate)
|
||||
{
|
||||
$data = $this->checkParam($validate);
|
||||
if (!empty($data['mer_phone'])) {
|
||||
$newUid = Db::name('User')->where('account', $data['mer_phone'])->value('uid', 0);
|
||||
if ($newUid) {
|
||||
return app('json')->fail('该商家手机号已存在账户,请更换手机');
|
||||
}
|
||||
}
|
||||
$this->repository->createMerchant($data);
|
||||
return app('json')->success('添加成功');
|
||||
}
|
||||
@ -143,6 +149,11 @@ class Merchant extends BaseController
|
||||
if (!$data['category_id'] || !$merchantCategoryRepository->exists($data['category_id']))
|
||||
return app('json')->fail('商户分类不存在');
|
||||
|
||||
$newUid = Db::name('User')->where('account', $data['mer_phone'])->value('uid', -1);
|
||||
$merId = Db::name('Merchant')->where('uid', $newUid)->value('mer_id', 0);
|
||||
if ($newUid != -1 && $id != $merId) {
|
||||
return app('json')->fail('该商家手机号已存在账户,请更换手机');
|
||||
}
|
||||
unset($data['mer_account'], $data['mer_password']);
|
||||
$margin = $this->repository->checkMargin($id, $data['type_id']);
|
||||
$data['margin'] = $margin['margin'];
|
||||
|
@ -43,6 +43,7 @@ use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
use think\facade\Queue;
|
||||
use crmeb\jobs\SendSmsJob;
|
||||
use crmeb\jobs\TestJob;
|
||||
use app\controller\api\Ceshi;
|
||||
|
||||
/**
|
||||
@ -53,6 +54,12 @@ use app\controller\api\Ceshi;
|
||||
*/
|
||||
class Auth extends BaseController
|
||||
{
|
||||
public function dotest()
|
||||
{
|
||||
Queue::push(SendSmsJob::class, ['tempId' => 'ORDER_CREATE', 'id' => 101]);
|
||||
return app('json')->success();
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$type = $this->request->param('type');
|
||||
@ -196,8 +203,8 @@ class Auth extends BaseController
|
||||
$data['is_wsxx'] = 0;
|
||||
|
||||
$data['mer_info'] = [];
|
||||
// 判断是否是商户,并且有没有完善信息
|
||||
//这里有点小问题以后要修改
|
||||
// 判断是否是商户,并且有没有完善信息
|
||||
// 这里有点小问题以后要修改
|
||||
$store_service = Db::name('store_service')->where('uid', $data['uid'])->find();
|
||||
if ($store_service) {
|
||||
$mer_arr = Db::name('merchant')->where('mer_id', $store_service['mer_id'])->where('is_del', 0)->where('status', 1)->field('type_id,mer_avatar,mer_banner,mer_info,category_id,service_phone,mer_address,uid,mer_name')->find();
|
||||
@ -393,6 +400,25 @@ class Auth extends BaseController
|
||||
return app('json')->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定极光register_id
|
||||
* @param UserRepository $repository
|
||||
* @return mixed
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function bindJg(UserRepository $repository)
|
||||
{
|
||||
$phone = $this->request->param('phone');
|
||||
$jgRegisterId = $this->request->param('jg_register_id');
|
||||
$user = $repository->accountByUser($phone);
|
||||
if ($user->save(['jg_register_id' => $jgRegisterId]) === false) {
|
||||
return app('json')->fail('绑定失败');
|
||||
}
|
||||
return app('json')->success();
|
||||
}
|
||||
|
||||
public function getCaptcha()
|
||||
{
|
||||
$codeBuilder = new CaptchaBuilder(null, new PhraseBuilder(4));
|
||||
@ -843,4 +869,183 @@ class Auth extends BaseController
|
||||
return app('json')->success('短信发送成功');
|
||||
}
|
||||
|
||||
//物流系统扫码取货确认商家发货
|
||||
public function deliveryGoods($id)
|
||||
{
|
||||
$orderSn = $this->request->param('order_sn');
|
||||
$logisticsCode = $this->request->param('logistics_code') ?? '';
|
||||
if (empty($orderSn)) {
|
||||
return app('json')->fail('参数order_sn不能为空');
|
||||
}
|
||||
if (empty($logisticsCode)) {
|
||||
app()->make(StoreOrderRepository::class)->deliveryGoods($id, $orderSn);
|
||||
return app('json')->success('快递员扫描取件成功');
|
||||
} else {
|
||||
app()->make(StoreOrderRepository::class)->deliveryGoods($id, $orderSn, $logisticsCode);
|
||||
return app('json')->success('快递员已完成送货');
|
||||
}
|
||||
}
|
||||
|
||||
//根据地址信息查询汇总信息
|
||||
public function orderStatistics()
|
||||
{
|
||||
$cityCode = $this->request->param('city_code', '');
|
||||
$districtCode = $this->request->param('district_code', '');
|
||||
$streetCode = $this->request->param('street_code', '');
|
||||
$villageCode = $this->request->param('village_code', '');
|
||||
$brigadeId = $this->request->param('brigade_id', 0);
|
||||
$startDate = $this->request->param('start_date', '');
|
||||
$endDate = $this->request->param('end_date', '');
|
||||
$queryBuilder = Db::name('ProductOrderLog')->where('status', 1);
|
||||
if ($cityCode) {
|
||||
$queryBuilder = $queryBuilder->where('city_code', $cityCode);
|
||||
}
|
||||
if ($districtCode) {
|
||||
$queryBuilder = $queryBuilder->where('district_code', $districtCode);
|
||||
}
|
||||
if ($streetCode) {
|
||||
$queryBuilder = $queryBuilder->where('street_code', $streetCode);
|
||||
}
|
||||
if ($villageCode) {
|
||||
$queryBuilder = $queryBuilder->where('village_code', $villageCode);
|
||||
}
|
||||
if ($brigadeId) {
|
||||
$queryBuilder = $queryBuilder->where('brigade_id', $brigadeId);
|
||||
}
|
||||
if ($startDate) {
|
||||
$queryBuilder = $queryBuilder->whereTime('create_time', '>=', trim($startDate));
|
||||
}
|
||||
if ($endDate) {
|
||||
$queryBuilder = $queryBuilder->whereTime('create_time', '<=', trim($endDate) . ' 23:59:59');
|
||||
}
|
||||
$orderNum = $queryBuilder->count();
|
||||
$productNum = $queryBuilder->sum('product_num');
|
||||
$totalPrice = $queryBuilder->sum('total_price');
|
||||
$data = [
|
||||
'where' => $this->request->param(),
|
||||
'order_num' => $orderNum,
|
||||
'product_num' => $productNum,
|
||||
'total_price' => $totalPrice
|
||||
];
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
//根据地址信息查询订单列表
|
||||
public function orderList()
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$cityCode = $this->request->param('city_code', '');
|
||||
$districtCode = $this->request->param('district_code', '');
|
||||
$streetCode = $this->request->param('street_code', '');
|
||||
$villageCode = $this->request->param('village_code', '');
|
||||
$brigadeId = $this->request->param('brigade_id', 0);
|
||||
$startDate = $this->request->param('start_date', '');
|
||||
$endDate = $this->request->param('end_date', '');
|
||||
$queryBuilder = Db::name('ProductOrderLog')->where('status', 1);
|
||||
if ($cityCode) {
|
||||
$queryBuilder = $queryBuilder->where('city_code', $cityCode);
|
||||
}
|
||||
if ($districtCode) {
|
||||
$queryBuilder = $queryBuilder->where('district_code', $districtCode);
|
||||
}
|
||||
if ($streetCode) {
|
||||
$queryBuilder = $queryBuilder->where('street_code', $streetCode);
|
||||
}
|
||||
if ($villageCode) {
|
||||
$queryBuilder = $queryBuilder->where('village_code', $villageCode);
|
||||
}
|
||||
if ($brigadeId) {
|
||||
$queryBuilder = $queryBuilder->where('brigade_id', $brigadeId);
|
||||
}
|
||||
if ($startDate) {
|
||||
$queryBuilder = $queryBuilder->whereTime('create_time', '>=', trim($startDate));
|
||||
}
|
||||
if ($endDate) {
|
||||
$queryBuilder = $queryBuilder->whereTime('create_time', '<=', trim($endDate) . ' 23:59:59');
|
||||
}
|
||||
$count = $queryBuilder->count();
|
||||
$list = $queryBuilder->setOption('field', [])->field(['id', 'order_id', 'product_num', 'product_price', 'total_price', 'city_code', 'district_code', 'street_code', 'village_code', 'brigade_id', 'create_time'])->order('id', 'desc')->page($page, $limit)->fetchSql(false)->select();
|
||||
$orderIdList = [];
|
||||
if ($list) {
|
||||
$orderIdArray = $list->column('order_id');
|
||||
if (count($orderIdArray) > 0) {
|
||||
$orderIdList = Db::name('store_order')->whereIn('order_id', $orderIdArray)->fetchSql(false)->column('order_sn', 'order_id');
|
||||
}
|
||||
$list = $list->toArray();
|
||||
};
|
||||
foreach($list as $k=>$v) {
|
||||
$list[$k]['order_sn'] = !empty($orderIdList[$v['order_id']]) ? $orderIdList[$v['order_id']] : '';
|
||||
}
|
||||
return app('json')->success(compact('count', 'list'));
|
||||
}
|
||||
|
||||
//根据地址信息查询商家数
|
||||
public function merStatistics()
|
||||
{
|
||||
$districtCode = $this->request->param('district_code', '');
|
||||
$streetCode = $this->request->param('street_code', '');
|
||||
$villageCode = $this->request->param('village_code', '');
|
||||
$startDate = $this->request->param('start_date', '');
|
||||
$endDate = $this->request->param('end_date', '');
|
||||
$villageId = Db::name('GeoVillage')->where('village_code', $villageCode)->fetchSql(false)->value('village_id', 0);
|
||||
$queryBuilder = Db::name('Merchant')->where('status', 1);
|
||||
|
||||
if ($districtCode) {
|
||||
$queryBuilder = $queryBuilder->where('area_id', $districtCode);
|
||||
}
|
||||
if ($streetCode) {
|
||||
$queryBuilder = $queryBuilder->where('street_id', $streetCode);
|
||||
}
|
||||
if ($villageId) {
|
||||
$queryBuilder = $queryBuilder->where('village_id', $villageId);
|
||||
}
|
||||
if ($startDate) {
|
||||
$queryBuilder = $queryBuilder->whereTime('create_time', '>=', trim($startDate));
|
||||
}
|
||||
if ($endDate) {
|
||||
$queryBuilder = $queryBuilder->whereTime('create_time', '<=', trim($endDate) . ' 23:59:59');
|
||||
}
|
||||
$merNum = $queryBuilder->fetchSql(false)->count();
|
||||
$data = [
|
||||
'where' => $this->request->param(),
|
||||
'mer_num' => $merNum
|
||||
];
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
//根据地址信息查询商品数
|
||||
public function goodsStatistics()
|
||||
{
|
||||
$districtCode = $this->request->param('district_code', '');
|
||||
$streetCode = $this->request->param('street_code', '');
|
||||
$villageCode = $this->request->param('village_code', '');
|
||||
$startDate = $this->request->param('start_date', '');
|
||||
$endDate = $this->request->param('end_date', '');
|
||||
$villageId = Db::name('GeoVillage')->where('village_code', $villageCode)->fetchSql(false)->value('village_id', 0);
|
||||
$queryBuilder = Db::name('Merchant')->where('status', 1);
|
||||
if ($districtCode) {
|
||||
$queryBuilder = $queryBuilder->where('area_id', $districtCode);
|
||||
}
|
||||
if ($streetCode) {
|
||||
$queryBuilder = $queryBuilder->where('street_id', $streetCode);
|
||||
}
|
||||
if ($villageId) {
|
||||
$queryBuilder = $queryBuilder->where('village_id', $villageId);
|
||||
}
|
||||
$merIdArray = $queryBuilder->fetchSql(false)->column('mer_id');
|
||||
$prodQueryBuilder = Db::name('StoreProduct')->where('is_show', 1)->where('status', 1)->whereIn('mer_id', $merIdArray);
|
||||
if ($startDate) {
|
||||
$prodQueryBuilder = $prodQueryBuilder->whereTime('create_time', '>=', trim($startDate));
|
||||
}
|
||||
if ($endDate) {
|
||||
$prodQueryBuilder = $prodQueryBuilder->whereTime('create_time', '<=', trim($endDate) . ' 23:59:59');
|
||||
}
|
||||
$goodsNum = $prodQueryBuilder->fetchSql(false)->count();
|
||||
$data = [
|
||||
'where' => $this->request->param(),
|
||||
'goods_num' => $goodsNum
|
||||
];
|
||||
return app('json')->success($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ class Common extends BaseController
|
||||
*/
|
||||
public function wechatCombinePayNotify($type)
|
||||
{
|
||||
if (!in_array($type, ['order', 'presell'], true))
|
||||
if (!in_array($type, ['order', 'presell', 'order_settle'], true))
|
||||
throw new ValidateException('参数错误');
|
||||
try {
|
||||
return WechatService::create()->handleCombinePayNotify($type);
|
||||
|
@ -12,18 +12,24 @@
|
||||
|
||||
namespace app\controller\api\community;
|
||||
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\community\CommunityRepository;
|
||||
use app\common\repositories\store\order\StoreOrderProductRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\store\product\ProductRepository;
|
||||
use app\common\repositories\system\RelevanceRepository;
|
||||
use app\common\repositories\user\UserHistoryRepository;
|
||||
use app\common\repositories\user\UserRelationRepository;
|
||||
use app\common\repositories\user\UserRepository;
|
||||
use app\common\service\JgPush;
|
||||
use app\validate\api\CommunityValidate;
|
||||
use crmeb\basic\BaseController;
|
||||
use crmeb\services\MiniProgramService;
|
||||
use think\App;
|
||||
use app\common\repositories\community\CommunityRepository as repository;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class Community extends BaseController
|
||||
{
|
||||
@ -54,7 +60,7 @@ class Community extends BaseController
|
||||
*/
|
||||
public function lst()
|
||||
{
|
||||
$where = $this->request->params(['keyword','topic_id','is_hot','category_id','spu_id']);
|
||||
$where = $this->request->params(['keyword','topic_id','is_hot','category_id','spu_id', 'is_type', 'resale_type']);
|
||||
if (!$where['category_id']) {
|
||||
unset($where['category_id']);
|
||||
} else if ($where['category_id'] == -1) {
|
||||
@ -266,7 +272,7 @@ class Community extends BaseController
|
||||
|
||||
public function checkParams()
|
||||
{
|
||||
$data = $this->request->params(['image','topic_id','content','spu_id','order_id',['is_type',1],'video_link']);
|
||||
$data = $this->request->params(['image','topic_id','content','spu_id','order_id',['is_type',1],'video_link', 'resale_type', 'product_info']);
|
||||
$config = systemConfig(["community_app_switch",'community_audit','community_video_audit']);
|
||||
$data['status'] = 0;
|
||||
$data['is_show'] = 0;
|
||||
@ -278,7 +284,7 @@ class Community extends BaseController
|
||||
$data['is_show'] = 1;
|
||||
$data['status_time'] = date('Y-m-d H:i:s', time());
|
||||
}
|
||||
} else {
|
||||
} elseif ($data['is_type'] == 2) {
|
||||
if (!in_array($this->repository::COMMUNIT_TYPE_VIDEO,$config['community_app_switch']))
|
||||
throw new ValidateException('短视频未开启');
|
||||
if ($config['community_video_audit']) {
|
||||
@ -287,9 +293,7 @@ class Community extends BaseController
|
||||
$data['status_time'] = date('Y-m-d H:i:s', time());
|
||||
}
|
||||
if (!$data['video_link']) throw new ValidateException('请上传视频');
|
||||
|
||||
}
|
||||
|
||||
$data['content'] = filter_emoji($data['content']);
|
||||
MiniProgramService::create()->msgSecCheck($this->request->userInfo(), $data['content'],3,0);
|
||||
app()->make(CommunityValidate::class)->check($data);
|
||||
@ -425,4 +429,201 @@ class Community extends BaseController
|
||||
if (!$url) return app('json')->fail('二维码生成失败');
|
||||
return app('json')->success(compact('url'));
|
||||
}
|
||||
|
||||
public function getOrderList()
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$keyword = $this->request->param('keyword');
|
||||
/** @var StoreOrderRepository $repo */
|
||||
$repo = app()->make(StoreOrderRepository::class);
|
||||
$list = $repo->purchaseOrder(['uid' => $this->request->uid()], $keyword, $page, $limit);
|
||||
return app('json')->success($list);
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$keyword = $this->request->param('keyword');
|
||||
$list = app()->make(ProductRepository::class)->communityProduct(['uid' => $this->request->uid()], $keyword, $page, $limit);
|
||||
return app('json')->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转售加购
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function addCart()
|
||||
{
|
||||
$communityId = $this->request->param('community_id');
|
||||
$cartIds = $this->repository->addCart($this->request->uid(), $communityId);
|
||||
return app('json')->success(['cart_id' => $cartIds]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转售商品列表
|
||||
* @return mixed
|
||||
*/
|
||||
public function resaleList()
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$status = $this->request->param('status');
|
||||
$queryBuilder = Db::name('community')->alias('c')->leftJoin('resale r','c.community_id = r.community_id')->where('c.is_type', 3)->where('c.is_del', 0)->where('c.uid', $this->request->uid());
|
||||
// 在售商品
|
||||
if ($status == 1) {
|
||||
$queryBuilder->where('c.status', 1)->where('c.is_show', 1)->where(function ($query) {
|
||||
$query->where(function ($conn) {
|
||||
$conn->where('c.resale_type', 1)->where('r.status', 0);
|
||||
});
|
||||
$query->whereOr(function ($conn) {
|
||||
$conn->where('c.resale_type', 2)->where('c.mer_status', 1)->where('r.status', 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
// 已售出商品
|
||||
if ($status == 2) {
|
||||
$queryBuilder->where('c.status', 1)->where('r.status', 1);
|
||||
}
|
||||
// 待审核
|
||||
if ($status == 3) {
|
||||
$queryBuilder->where('c.status', 0);
|
||||
}
|
||||
// 审核未通过
|
||||
if ($status == 4) {
|
||||
$queryBuilder->where('c.status', -1);
|
||||
}
|
||||
// 审核通过
|
||||
if ($status == 5) {
|
||||
$queryBuilder->where('c.status', 1);
|
||||
}
|
||||
$count = $queryBuilder->count();
|
||||
$list = $queryBuilder->setOption('field', [])->field(['c.community_id', 'c.title', 'c.image', 'c.resale_type', 'c.mer_status', 'SUM(`r`.`number` * `r`.`price`) AS total_price', 'SUM(`r`.`number` * `r`.`price` * (100 - `r`.`float_rate`) / 100) AS discount_price'])->group('c.community_id')->order('c.community_id', 'desc')->page($page, $limit)->fetchSql(false)->select();
|
||||
if ($list) $list = $list->toArray();
|
||||
foreach($list as $k=>&$v) {
|
||||
$list[$k]['discount_price'] = round($v['discount_price'], 2);
|
||||
}
|
||||
return app('json')->success(compact('count', 'list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除转售商品
|
||||
* @return mixed
|
||||
*/
|
||||
public function deleteResale($id)
|
||||
{
|
||||
$communityInfo = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->find();
|
||||
if (!$communityInfo) {
|
||||
return app('json')->fail('转售商品不存在');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$list = Db::name('resale')->where('community_id', $id)->where('is_del', 0)->where('status', 0)->select();
|
||||
foreach($list as $prod) {
|
||||
Db::name('store_product')->where('product_id', $prod['product_id'])->inc('stock', $prod['number'])->update();
|
||||
Db::name('store_product_attr_value')->where('product_id', $prod['product_id'])->where('unique', $prod['product_attr_unique'])->inc('stock', $prod['number'])->update();
|
||||
}
|
||||
Db::name('resale')->where('community_id', $id)->where('status', 0)->update(['is_del' => 1]);
|
||||
Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->update(['is_del' => 1]);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return app('json')->fail('删除转售商品失败');
|
||||
}
|
||||
return app('json')->success('删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核转售商品结算价
|
||||
* @return mixed
|
||||
*/
|
||||
public function checkResale($id)
|
||||
{
|
||||
$communityInfo = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->find();
|
||||
if (!$communityInfo) {
|
||||
return app('json')->fail('转售商品不存在');
|
||||
}
|
||||
$status = $this->request->param('status');
|
||||
if (!$status) {
|
||||
app('json')->fail('请设置审核状态');
|
||||
}
|
||||
if ($status == 1) {
|
||||
Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->update(['status' => $status, 'mer_status' => 1]);
|
||||
}
|
||||
if ($status == 2) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
$list = Db::name('resale')->where('community_id', $id)->where('is_del', 0)->where('status', 0)->select();
|
||||
foreach($list as $prod) {
|
||||
Db::name('store_product')->where('product_id', $prod['product_id'])->inc('stock', $prod['number'])->update();
|
||||
Db::name('store_product_attr_value')->where('product_id', $prod['product_id'])->where('unique', $prod['product_attr_unique'])->inc('stock', $prod['number'])->update();
|
||||
}
|
||||
Db::name('resale')->where('community_id', $id)->where('status', 0)->update(['is_del' => 1]);
|
||||
Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->update(['is_del' => 1, 'status' => $status, 'mer_status' => 2]);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return app('json')->fail('审核商品折扣价失败');
|
||||
}
|
||||
}
|
||||
return app('json')->success('审核操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 转售商品详情
|
||||
* @return mixed
|
||||
*/
|
||||
public function resaleDetail($id)
|
||||
{
|
||||
$communityInfo = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->find();
|
||||
if (!$communityInfo) {
|
||||
return app('json')->fail('转售商品不存在');
|
||||
}
|
||||
return app('json')->success($this->repository->show($id, $this->user));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑转售商品
|
||||
* @return mixed
|
||||
*/
|
||||
public function editResale($id)
|
||||
{
|
||||
$communityInfo = Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->where('is_del', 0)->find();
|
||||
if (!$communityInfo) {
|
||||
return app('json')->fail('转售商品不存在');
|
||||
}
|
||||
$data = $this->checkParams();
|
||||
$this->checkUserAuth();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$list = Db::name('resale')->where('community_id', $id)->where('is_del', 0)->where('status', 0)->select();
|
||||
foreach($list as $prod) {
|
||||
Db::name('store_product')->where('product_id', $prod['product_id'])->inc('stock', $prod['number'])->update();
|
||||
Db::name('store_product_attr_value')->where('product_id', $prod['product_id'])->where('unique', $prod['product_attr_unique'])->inc('stock', $prod['number'])->update();
|
||||
}
|
||||
Db::name('resale')->where('community_id', $id)->where('status', 0)->update(['is_del' => 1]);
|
||||
Db::name('community')->where('uid', $this->request->uid())->where('community_id', $id)->update(['is_del' => 1, 'status' => -1]);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
return app('json')->fail('编辑转售商品失败');
|
||||
}
|
||||
$data['uid'] = $this->request->uid();
|
||||
$res = $this->repository->create($data);
|
||||
return app('json')->success(['community_id' => $res]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布委托商品
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function entrust()
|
||||
{
|
||||
$data = $this->checkParams();
|
||||
$this->checkUserAuth();
|
||||
$data['uid'] = $this->request->uid();
|
||||
$res = $this->repository->create($data);
|
||||
return app('json')->success(['community_id' => $res]);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
namespace app\controller\api\server;
|
||||
|
||||
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\repositories\delivery\DeliveryStationRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\store\order\StoreRefundOrderRepository;
|
||||
@ -35,10 +36,10 @@ class StoreOrder extends BaseController
|
||||
|
||||
public function orderStatistics($merId, StoreOrderRepository $repository)
|
||||
{
|
||||
|
||||
$product_type=$this->request->param('product_type',0);
|
||||
$order = $repository->OrderTitleNumber($merId, null,$product_type);
|
||||
$order['refund'] = app()->make(StoreRefundOrderRepository::class)->getWhereCount(['is_system_del' => 0, 'mer_id' => $merId]);
|
||||
/** @var Common $common */
|
||||
$common = app()->make(Common::class);
|
||||
$data = [];
|
||||
$data['today'] = $common->mainGroup('today', $merId);
|
||||
@ -199,6 +200,17 @@ class StoreOrder extends BaseController
|
||||
return app('json')->success('发货成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 扫描发货
|
||||
* @param $orderId
|
||||
* @param $orderSn
|
||||
*/
|
||||
public function deliveryGoods($orderId, $orderSn, StoreOrderRepository $repository)
|
||||
{
|
||||
app()->make(StoreOrderRepository::class)->takeGoods($orderId, $orderSn);
|
||||
return app('json')->success('扫描发货成功');
|
||||
}
|
||||
|
||||
public function payPrice($merId, StoreOrderRepository $repository)
|
||||
{
|
||||
list($start, $stop, $month) = $this->request->params([
|
||||
@ -338,4 +350,57 @@ class StoreOrder extends BaseController
|
||||
return app('json')->success('订单核销成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单结算
|
||||
* @return mixed
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
*/
|
||||
public function settle(StoreOrderRepository $repository)
|
||||
{
|
||||
$id = $this->request->param('id/d');
|
||||
$payType = $this->request->param('pay_type');
|
||||
if ($payType == 'creditBuy') {
|
||||
return app('json')->fail('支付方式不支持');
|
||||
}
|
||||
try {
|
||||
$data = $repository->settle($id, $payType, $this->request->userInfo());
|
||||
return app('json')->success('success', $data);
|
||||
} catch (\Exception $e) {
|
||||
return app('json')->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认接单
|
||||
* @return mixed
|
||||
*/
|
||||
public function confirm(StoreOrderRepository $repository)
|
||||
{
|
||||
$id = $this->request->param('id/d');
|
||||
$type = $this->request->param('type/d');
|
||||
try {
|
||||
$repository->confirm($id, $type);
|
||||
return app('json')->success('success');
|
||||
} catch (\Exception $e) {
|
||||
return app('json')->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购订单列表
|
||||
* @param $merId
|
||||
* @param StoreOrderRepository $orderRepository
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function purchaseOrder($merId, StoreOrderRepository $orderRepository)
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$keyword = $this->request->param('keyword');
|
||||
$list = $orderRepository->purchaseOrder(['mer_id' => $merId], $keyword, $page, $limit);
|
||||
return app('json')->success($list);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -216,4 +216,17 @@ class StoreProduct extends BaseController
|
||||
$this->repository->update($id, ['is_good' => $is_good]);
|
||||
return app('json')->success('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品入库
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function stockIn()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$this->repository->stockIn($this->merId, $params);
|
||||
return app('json')->success('入库成功');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
namespace app\controller\api\store\merchant;
|
||||
|
||||
use app\common\model\store\order\StoreOrderInterest;
|
||||
use app\common\repositories\store\MerchantTakeRepository;
|
||||
use app\common\repositories\store\product\ProductRepository;
|
||||
use app\common\repositories\system\config\ConfigValueRepository;
|
||||
@ -54,7 +55,7 @@ class Merchant extends BaseController
|
||||
public function lst()
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$where = $this->request->params(['keyword', 'order', 'is_best', 'location', 'category_id', 'type_id','is_trader', 'street_id']);
|
||||
$where = $this->request->params(['keyword', 'order', 'is_best', 'location', 'category_id', 'type_id','is_trader', 'street_id', 'credit_buy']);
|
||||
if (empty($where['type_id'])) {
|
||||
$where['type_id'] = [MerchantModel::TypeCloudWarehouse, MerchantModel::TypeStore, MerchantModel::TypeSupplyChain, MerchantModel::TypePlatform];
|
||||
}
|
||||
@ -163,6 +164,9 @@ class Merchant extends BaseController
|
||||
'long',
|
||||
'lat',
|
||||
['delivery_way',[2]],
|
||||
'credit_buy',
|
||||
'settle_cycle',
|
||||
'interest_rate',
|
||||
]);
|
||||
|
||||
// 如果手机号不存在,则使用入驻时的手机号
|
||||
@ -247,8 +251,8 @@ class Merchant extends BaseController
|
||||
|
||||
public function apply($merId){
|
||||
$merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find();
|
||||
if ($this->userInfo['uid'] != $merchant->uid){
|
||||
return app('json')->fail('你不是管理员无法进行提现操作');
|
||||
if (($msg = $this->checkAuth($merchant)) !== true) {
|
||||
return app('json')->fail($msg);
|
||||
}
|
||||
$extract_minimum_line = systemConfig('extract_minimum_line') ?: 0;
|
||||
$extract_minimum_num = systemConfig('extract_minimum_num');
|
||||
@ -280,8 +284,8 @@ class Merchant extends BaseController
|
||||
{
|
||||
$data = $this->request->param(['extract_money','financial_type', 'financial_bank_name', 'financial_bank_bank', 'financial_bank_code', 'financial_bank_branch']);
|
||||
$merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('reg_admin_id,uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find();
|
||||
if ($this->userInfo['uid'] != $merchant->uid){
|
||||
return app('json')->fail('你不是管理员无法进行提现操作');
|
||||
if (($msg = $this->checkAuth($merchant)) !== true) {
|
||||
return app('json')->fail($msg);
|
||||
}
|
||||
$bankInfo = [
|
||||
'name' => $data['financial_bank_name'],
|
||||
@ -299,8 +303,8 @@ class Merchant extends BaseController
|
||||
public function listApply($merId)
|
||||
{
|
||||
$merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('reg_admin_id,uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find();
|
||||
if ($this->userInfo['uid'] != $merchant->uid){
|
||||
return app('json')->fail('你不是管理员无法进行提现操作');
|
||||
if (($msg = $this->checkAuth($merchant)) !== true) {
|
||||
return app('json')->fail($msg);
|
||||
}
|
||||
[$page, $limit] = $this->getPage();
|
||||
$where['mer_id'] = $merId;
|
||||
@ -312,8 +316,8 @@ class Merchant extends BaseController
|
||||
public function account($merId)
|
||||
{
|
||||
$merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find();
|
||||
if ($this->userInfo['uid'] != $merchant->uid){
|
||||
return app('json')->fail('你不是管理员无法进行提现操作');
|
||||
if (($msg = $this->checkAuth($merchant)) !== true) {
|
||||
return app('json')->fail($msg);
|
||||
}
|
||||
$data = [
|
||||
'financial_bank' => $merchant->financial_bank,//银行卡信息
|
||||
@ -329,8 +333,8 @@ class Merchant extends BaseController
|
||||
$data = $this->request->param(['name','bank','bank_code','financial_type']);
|
||||
app()->make(MerchantFinancialAccountValidate::class)->check($data);
|
||||
$merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find();
|
||||
if ($this->userInfo['uid'] != $merchant->uid){
|
||||
return app('json')->fail('你不是管理员无法进行提现操作');
|
||||
if (($msg = $this->checkAuth($merchant)) !== true) {
|
||||
return app('json')->fail($msg);
|
||||
}
|
||||
$update = [
|
||||
'name' => $data['name'],
|
||||
@ -340,4 +344,16 @@ class Merchant extends BaseController
|
||||
app()->make(MerchantRepository::class)->update($merId,['financial_bank' => json_encode($update),'financial_type' => 1]);
|
||||
return app('json')->success('提交成功');
|
||||
}
|
||||
|
||||
public function checkAuth($merchant)
|
||||
{
|
||||
if ($this->userInfo['uid'] != $merchant->uid) {
|
||||
return '你不是管理员无法进行提现操作';
|
||||
}
|
||||
$unSettleCount = StoreOrderInterest::where('mer_id', $merchant->mer_id)->where('status', StoreOrderInterest::STATUS_UNSETTLED)->whereTime('start_time', '<=', time())->count();
|
||||
if ($unSettleCount > 0) {
|
||||
return '有未结清的订单,请结清订单后再进行提现';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ use crmeb\services\SmsService;
|
||||
use crmeb\services\SwooleTaskService;
|
||||
use crmeb\services\YunxinSmsService;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
use crmeb\basic\BaseController;
|
||||
use app\common\repositories\system\merchant\MerchantIntentionRepository as repository;
|
||||
use think\exception\ValidateException;
|
||||
@ -44,6 +45,14 @@ class MerchantIntention extends BaseController
|
||||
return app('json')->fail('未开启商户入驻');
|
||||
}
|
||||
if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
|
||||
$newUid = Db::name('User')->where('account', $data['phone'])->value('uid', -1);
|
||||
if ($newUid != -1 && $this->userInfo->uid != $newUid) {
|
||||
throw new ValidateException('该申请手机已存在账户,不可申请');
|
||||
}
|
||||
$newMerid = Db::name('Merchant')->where('mer_phone', $data['phone'])->value('mer_id', -1);
|
||||
if ($newMerid != -1) {
|
||||
throw new ValidateException('该申请手机已存在商户,不可申请');
|
||||
}
|
||||
$make = app()->make(MerchantRepository::class);
|
||||
if ($make->fieldExists('mer_name', $data['mer_name']))
|
||||
throw new ValidateException('商户名称已存在,不可申请');
|
||||
@ -72,6 +81,9 @@ class MerchantIntention extends BaseController
|
||||
if (!systemConfig('mer_intention_open')) {
|
||||
return app('json')->fail('未开启商户入驻');
|
||||
}
|
||||
if (!empty($data['mer_phone'])) {
|
||||
unset($data['mer_phone']);
|
||||
}
|
||||
$data['create_time'] = date('Y-m-d H:i:s', time());
|
||||
$this->repository->updateIntention((int)$id, $data);
|
||||
SwooleTaskService::admin('notice', [
|
||||
|
@ -14,6 +14,7 @@
|
||||
namespace app\controller\api\store\order;
|
||||
|
||||
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\repositories\delivery\DeliveryOrderRepository;
|
||||
use app\common\repositories\store\order\StoreOrderCreateRepository;
|
||||
use app\common\repositories\store\order\StoreOrderReceiptRepository;
|
||||
@ -22,10 +23,12 @@ use crmeb\basic\BaseController;
|
||||
use app\common\repositories\store\order\StoreCartRepository;
|
||||
use app\common\repositories\store\order\StoreGroupOrderRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\user\UserAddressRepository;
|
||||
use think\exception\ValidateException;
|
||||
use crmeb\services\ExpressService;
|
||||
use crmeb\services\LockService;
|
||||
use think\facade\Db;
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
@ -80,12 +83,10 @@ class StoreOrder extends BaseController
|
||||
$mark = (array)$this->request->param('mark', []);
|
||||
$payType = $this->request->param('pay_type');
|
||||
$post = (array)$this->request->param('post');
|
||||
|
||||
$isPc = $payType === 'pc';
|
||||
if ($isPc) {
|
||||
$payType = 'balance';
|
||||
}
|
||||
|
||||
if (!in_array($payType, StoreOrderRepository::PAY_TYPE, true))
|
||||
return app('json')->fail('请选择正确的支付方式');
|
||||
|
||||
@ -98,8 +99,30 @@ class StoreOrder extends BaseController
|
||||
$uid = $this->request->uid();
|
||||
if (!($count = count($cartId)) || $count != count($cartRepository->validIntersection($cartId, $uid)))
|
||||
return app('json')->fail('数据无效');
|
||||
// if (!$addressId)
|
||||
// return app('json')->fail('请选择地址');
|
||||
|
||||
if ($addressId) {
|
||||
$deliveryWay = !empty($takes[0]) ? $takes[0] : 0;
|
||||
$addressRepository = app()->make(UserAddressRepository::class);
|
||||
$address = $addressRepository->getWhere(['uid' => $uid, 'address_id' => $addressId]);
|
||||
$cartProductType = Db::name('StoreCart')->where('cart_id', $cartId[0] ?? 0)->value('product_type');
|
||||
if ($cartProductType == 0 && $deliveryWay != 1) {
|
||||
$userAddressCode = ($address['province_code'] ?? '') . ',' . ($address['city_code'] ?? '') . ',' . ($address['district_code'] ?? '') . ',' . ($address['street_code'] ?? '') . ',' . ($address['village_code'] ?? '') . ',' . ($address['brigade_id'] ?? 0);
|
||||
$getUrl = env('LOGISTICS_HOST_URL') . '/api/hasCourier?user_address_code=' . $userAddressCode;
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $getUrl);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
|
||||
$hasCourierData = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
if (!empty($hasCourierData) && is_string($hasCourierData)) {
|
||||
$courierData = json_decode($hasCourierData, true);
|
||||
if (empty($courierData['code']) || $courierData['code'] != 1) {
|
||||
throw new ValidateException('该收货区域未配送快递员');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$groupOrder = app()->make(LockService::class)->exec('order.create', function () use ($orderCreateRepository, $receipt_data, $mark, $extend, $cartId, $payType, $takes, $couponIds, $useIntegral, $addressId, $post) {
|
||||
return $orderCreateRepository->v2CreateOrder(array_search($payType, StoreOrderRepository::PAY_TYPE), $this->request->userInfo(), $cartId, $extend, $mark, $receipt_data, $takes, $couponIds, $useIntegral, $addressId, $post);
|
||||
@ -109,8 +132,8 @@ class StoreOrder extends BaseController
|
||||
$this->repository->paySuccess($groupOrder);
|
||||
return app('json')->status('success', '支付成功', ['order_id' => $groupOrder['group_order_id']]);
|
||||
}
|
||||
if ($isPc) {
|
||||
return app('json')->success(['order_id' => $groupOrder->group_order_id]);
|
||||
if ($isPc || $groupOrder['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY) {
|
||||
return app('json')->status('error', '等待确认订单', ['order_id' => $groupOrder['group_order_id']]);
|
||||
}
|
||||
try {
|
||||
return $this->repository->pay($payType, $this->request->userInfo(), $groupOrder, $this->request->param('return_url'), $this->request->isApp());
|
||||
@ -134,7 +157,6 @@ class StoreOrder extends BaseController
|
||||
$where['product_type'] = $this->request->param('product_type',0);
|
||||
$where['search'] = $this->request->param('store_name');
|
||||
$where['uid'] = $this->request->uid();
|
||||
$where['paid'] = 1;
|
||||
$where['is_user'] = 1;
|
||||
return app('json')->success($this->repository->getList($where, $page, $limit));
|
||||
}
|
||||
@ -163,7 +185,8 @@ class StoreOrder extends BaseController
|
||||
*/
|
||||
public function number()
|
||||
{
|
||||
return app('json')->success(['orderPrice' => $this->request->userInfo()->pay_price] + $this->repository->userOrderNumber($this->request->uid()));
|
||||
$productType = $this->request->param('product_type', 0);
|
||||
return app('json')->success($this->repository->userOrderNumber($this->request->uid(), $productType));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,7 +198,8 @@ class StoreOrder extends BaseController
|
||||
public function groupOrderList(StoreGroupOrderRepository $groupOrderRepository)
|
||||
{
|
||||
[$page, $limit] = $this->getPage();
|
||||
$list = $groupOrderRepository->getList(['uid' => $this->request->uid(), 'paid' => 0], $page, $limit);
|
||||
$productType = $this->request->param('product_type', 0);
|
||||
$list = $groupOrderRepository->getList(['uid' => $this->request->uid(), 'paid' => 0, 'product_type' => $productType], $page, $limit);
|
||||
return app('json')->success($list);
|
||||
}
|
||||
|
||||
@ -193,7 +217,7 @@ class StoreOrder extends BaseController
|
||||
if (!$groupOrder)
|
||||
return app('json')->fail('订单不存在');
|
||||
else
|
||||
return app('json')->success($groupOrder->append(['cancel_time', 'cancel_unix'])->toArray());
|
||||
return app('json')->success($groupOrder);
|
||||
}
|
||||
|
||||
public function groupOrderStatus($id, StoreGroupOrderRepository $groupOrderRepository)
|
||||
@ -239,6 +263,9 @@ class StoreOrder extends BaseController
|
||||
if (!$groupOrder)
|
||||
return app('json')->fail('订单不存在或已支付');
|
||||
$this->repository->changePayType($groupOrder, array_search($type, StoreOrderRepository::PAY_TYPE));
|
||||
if ($groupOrder['pay_type'] == StoreGroupOrder::PAY_TYPE_CREDIT_BUY && !$groupOrder->orderList[0]->allowCreditPay()) {
|
||||
return app('json')->fail('请等待商家确认订单');
|
||||
}
|
||||
if ($groupOrder['pay_price'] == 0) {
|
||||
$this->repository->paySuccess($groupOrder);
|
||||
return app('json')->status('success', '支付成功', ['order_id' => $groupOrder['group_order_id']]);
|
||||
@ -277,6 +304,17 @@ class StoreOrder extends BaseController
|
||||
return app('json')->success(['qrcode' => $this->repository->wxQrcode($id, $order->verify_code)]);
|
||||
}
|
||||
|
||||
public function logisticsCode($id)
|
||||
{
|
||||
$storeInfo = Db::name('store_service')->where('uid', $this->request->uid())->find();
|
||||
if (!$storeInfo)
|
||||
return app('json')->fail('商户信息有误');
|
||||
$order = $this->repository->getWhere(['order_id' => $id, 'mer_id' => $storeInfo['mer_id'], 'is_del' => 0]);
|
||||
if (!$order)
|
||||
return app('json')->fail('订单状态有误');
|
||||
return app('json')->success(['qrcode' => $this->repository->logisticsQrcode($id, $order->order_sn)]);
|
||||
}
|
||||
|
||||
public function del($id)
|
||||
{
|
||||
$this->repository->userDel($id, $this->request->uid());
|
||||
@ -297,4 +335,5 @@ class StoreOrder extends BaseController
|
||||
$res = $orderRepository->show($id, $this->request->uid());
|
||||
return app('json')->success($res);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -130,6 +130,7 @@ class StoreRefundOrder extends BaseController
|
||||
if (!$order->refund_status)
|
||||
return app('json')->fail('订单已过退款/退货期限');
|
||||
if ($order->status < 0) return app('json')->fail('订单已退款');
|
||||
if ($order->status == 1) return app('json')->fail('订单已发货不支持退款');
|
||||
if ($order->status == 10) return app('json')->fail('订单不支持退款');
|
||||
if($order->is_virtual && $data['refund_type'] == 2) return app('json')->fail('订单不支持退款退货');
|
||||
if ($type == 1) {
|
||||
@ -151,11 +152,13 @@ class StoreRefundOrder extends BaseController
|
||||
public function lst()
|
||||
{
|
||||
$type = $this->request->param('type');
|
||||
$productType = $this->request->param('product_type', 0);
|
||||
[$page, $limit] = $this->getPage();
|
||||
return app('json')->success($this->repository->userList([
|
||||
'type' => $type,
|
||||
'uid' => $this->request->uid(),
|
||||
'is_del' => 0,
|
||||
'product_type' => $productType,
|
||||
], $page, $limit));
|
||||
}
|
||||
|
||||
|
@ -50,42 +50,13 @@ class StoreMicro extends BaseController
|
||||
public function ProductImport(){
|
||||
$product_id = $this->request->param('id', 0);
|
||||
$user = $this->request->userInfo();
|
||||
$mer_id =Db::name('store_service')->where('uid',$user['uid'])->where('status',1)->value('mer_id');
|
||||
if ($mer_id==0) return app('json')->fail('商户id不能为空');
|
||||
$find=Db::name('store_product')->where('product_id',$product_id)->find();
|
||||
if($find){
|
||||
if($find['product_type']!=0){
|
||||
return app('json')->fail('该商品不是普通商品');
|
||||
try {
|
||||
/** @var ProductRepository $productRepository */
|
||||
$productRepository = app()->make(ProductRepository::class);
|
||||
$a = $productRepository->import($product_id, $user);
|
||||
} catch (\Exception $e) {
|
||||
return app('json')->fail($e->getMessage());
|
||||
}
|
||||
$exist = Db::name('store_product')->where('old_product_id', $product_id)->where('mer_id', $mer_id)->find();
|
||||
if($exist){
|
||||
return app('json')->fail('已经导入过该商品了');
|
||||
}
|
||||
$find['attrValue']=Db::name('store_product_attr_value')->where('product_id',$find['product_id'])->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume')->select();
|
||||
$find['content']=Db::name('store_product_content')->where('product_id',$find['product_id'])->value('content');
|
||||
$find['is_show']=0;
|
||||
$find['mer_id']=$mer_id;
|
||||
$find['temp_id']="";
|
||||
$find['give_coupon_ids']=[];
|
||||
$find['params']=[];
|
||||
$find['extend']=[];
|
||||
$find['param_temp_id']=[];
|
||||
$find['mer_labels']=[];
|
||||
$find['attr']=[];
|
||||
$find['delivery_way']=[ 0 => "2"];
|
||||
$find["guarantee_template_id"] = "";
|
||||
$find['product_type']=0;
|
||||
$find['mer_cate_id']=[0 => 0];
|
||||
$find['is_used']=1;
|
||||
$find['status']=1;
|
||||
$find['mer_status']=1;
|
||||
$find['old_product_id']=$product_id;
|
||||
$find['slider_image']=explode(',',$find['slider_image']);
|
||||
unset($find['product_id'],$find['create_time']);
|
||||
}
|
||||
/** @var ProductRepository $make */
|
||||
$make = app()->make(ProductRepository::class);
|
||||
$a=$make->create($find,0);
|
||||
if($a){
|
||||
return app('json')->success(['data'=>$a,'msg'=>'导入成功']);
|
||||
}else{
|
||||
|
@ -16,6 +16,12 @@ namespace app\controller\api\user;
|
||||
use app\common\repositories\store\CityAreaRepository;
|
||||
use think\App;
|
||||
use crmeb\basic\BaseController;
|
||||
use app\common\model\store\GeoProvince;
|
||||
use app\common\model\store\GeoCity;
|
||||
use app\common\model\store\GeoArea;
|
||||
use app\common\model\store\GeoStreet;
|
||||
use app\common\model\store\GeoVillage;
|
||||
use app\common\model\store\GeoBrigade;
|
||||
use app\validate\api\UserAddressValidate as validate;
|
||||
use app\common\repositories\user\UserAddressRepository as repository;
|
||||
use think\exception\ValidateException;
|
||||
@ -50,7 +56,84 @@ class UserAddress extends BaseController
|
||||
if (!$this->repository->existsWhere(['address_id' => $id, 'uid' => $uid])) {
|
||||
return app('json')->fail('地址不存在');
|
||||
}
|
||||
return app('json')->success($this->repository->get($id, $uid));
|
||||
$addinfo = $this->repository->get($id, $uid);
|
||||
$area = [];
|
||||
if (!empty($addinfo['province_id'])) {
|
||||
$province = GeoProvince::where('province_id', $addinfo['province_id'])->find();
|
||||
if ($province) {
|
||||
$area[] = [
|
||||
'type' => 'province',
|
||||
'id' => $province->province_id,
|
||||
'level' => 1,
|
||||
'name' => $province->province_name ?? '',
|
||||
'code' => $province->province_code ?? ''
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
if (!empty($addinfo['city_id'])) {
|
||||
$city = GeoCity::where('city_id', $addinfo['city_id'])->find();
|
||||
if ($city) {
|
||||
$area[] = [
|
||||
'type' => 'city',
|
||||
'id' => $city['city_id'],
|
||||
'level' => 2,
|
||||
'name' => $city['city_name'] ?? '',
|
||||
'code' => $city['city_code'] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
if (!empty($addinfo['district_id'])) {
|
||||
$district = GeoArea::where('area_id', $addinfo['district_id'])->find();
|
||||
if ($district) {
|
||||
$area[] = [
|
||||
'type' => 'area',
|
||||
'id' => $district['area_id'],
|
||||
'level' => 3,
|
||||
'name' => $district['area_name'] ?? '',
|
||||
'code' => $district['area_code'] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
if (!empty($addinfo['street_id'])) {
|
||||
$street = GeoStreet::where('street_id', $addinfo['street_id'])->find();
|
||||
if ($street) {
|
||||
$area[] = [
|
||||
'type' => 'street',
|
||||
'id' => $street['street_id'],
|
||||
'level' => 4,
|
||||
'name' => $street['street_name'] ?? '',
|
||||
'code' => $street['street_code'] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
if (!empty($addinfo['village_id'])) {
|
||||
$village = GeoVillage::where('village_id', $addinfo['village_id'])->find();
|
||||
if ($village) {
|
||||
$area[] = [
|
||||
'type' => 'village',
|
||||
'id' => $village['village_id'],
|
||||
'level' => 5,
|
||||
'name' => $village['village_name'] ?? '',
|
||||
'code' => $village['village_code'] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
$addinfo->areas = $area;
|
||||
$addinfo->brigade = [];
|
||||
if (!empty($addinfo['brigade_id'])) {
|
||||
$brigade = GeoBrigade::where('id', $addinfo['brigade_id'])->find();
|
||||
if ($brigade) {
|
||||
$addinfo->brigade = [
|
||||
'type' => 'brigade',
|
||||
'id' => $brigade['id'],
|
||||
'level' => 6,
|
||||
'name' => $brigade['brigade_name'] ?? '',
|
||||
'code' => $brigade['brigade_name'] ?? ''
|
||||
];
|
||||
}
|
||||
}
|
||||
return app('json')->success($addinfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,30 +207,69 @@ class UserAddress extends BaseController
|
||||
*/
|
||||
public function checkParams(validate $validate)
|
||||
{
|
||||
$data = $this->request->params(['address_id', 'real_name', 'phone', 'area', 'detail', 'post_code', 'is_default']);
|
||||
$data = $this->request->params(['address_id', 'real_name', 'phone', 'area', 'detail', 'post_code', 'is_default', 'brigade']);
|
||||
$validate->check($data);
|
||||
[$province, $city, $district, $street] = ((array)$data['area']) + [null, null, null, null];
|
||||
$last = $street ?? $district ?? $city ?? $province;
|
||||
[$province, $city, $district, $street, $village] = ((array)$data['area']) + [null, null, null, null, null];
|
||||
$last = $village ?? $street ?? $district ?? $city ?? $province;
|
||||
if (!$last) {
|
||||
throw new ValidateException('请选择正确的收货地址');
|
||||
}
|
||||
$make = app()->make(CityAreaRepository::class);
|
||||
if (!$make->existsWhere(['id' => $last['id'], 'snum' => 0])) {
|
||||
throw new ValidateException('请手动选择所在地区');
|
||||
if (!$this->repository->villageExists('village_code', $last['code'])) {
|
||||
throw new ValidateException('地址信息错误');
|
||||
}
|
||||
if ($make->search([])->where('id', 'in', array_column($data['area'], 'id'))->count() !== count($data['area'])) {
|
||||
throw new ValidateException('请选择正确的收货地址');
|
||||
}
|
||||
|
||||
$data['province'] = $province['name'];
|
||||
$data['province_id'] = $province['id'];
|
||||
$data['province_code'] = '';
|
||||
if (!empty($data['province_id'])) {
|
||||
$province = GeoProvince::where('province_id', $data['province_id'])->find();
|
||||
if ($province) {
|
||||
$data['province_code'] = $province['province_code'];
|
||||
}
|
||||
}
|
||||
$data['city'] = $city['name'];
|
||||
$data['city_id'] = $city['id'];
|
||||
$data['city_code'] = '';
|
||||
if (!empty($data['city_id'])) {
|
||||
$city = GeoCity::where('city_id', $data['city_id'])->find();
|
||||
if ($city) {
|
||||
$data['city_code'] = $city['city_code'];
|
||||
}
|
||||
}
|
||||
$data['district'] = $district['name'];
|
||||
$data['district_id'] = $district['id'];
|
||||
$data['district_code'] = '';
|
||||
if (!empty($data['district_id'])) {
|
||||
$district = GeoArea::where('area_id', $data['district_id'])->find();
|
||||
if ($district) {
|
||||
$data['district_code'] = $district['area_code'];
|
||||
}
|
||||
}
|
||||
if (isset($street)) {
|
||||
$data['street'] = $street['name'];
|
||||
$data['street_id'] = $street['id'];
|
||||
$data['street'] = $street['name'] ?? '';
|
||||
$data['street_id'] = $street['id'] ?? 0;
|
||||
$data['street_code'] = '';
|
||||
if (!empty($data['street_id'])) {
|
||||
$street = GeoStreet::where('street_id', $data['street_id'])->find();
|
||||
if ($street) {
|
||||
$data['street_code'] = $street['street_code'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($village)) {
|
||||
$data['village'] = $village['name'] ?? '';
|
||||
$data['village_id'] = $village['id'] ?? 0;
|
||||
$data['village_code'] = '';
|
||||
if (!empty($data['village_id'])) {
|
||||
$village = GeoVillage::where('village_id', $data['village_id'])->find();
|
||||
if ($village) {
|
||||
$data['village_code'] = $village['village_code'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$brigade = $data['brigade'];
|
||||
if (isset($brigade)) {
|
||||
$data['brigade'] = $brigade['name'] ?? '';
|
||||
$data['brigade_id'] = $brigade['id'] ?? 0;
|
||||
}
|
||||
unset($data['area']);
|
||||
return $data;
|
||||
|
@ -17,6 +17,7 @@ use think\App;
|
||||
use crmeb\basic\BaseController;
|
||||
use app\common\repositories\store\shipping\CityRepository as repository;
|
||||
use think\facade\Log;
|
||||
use Overtrue\Pinyin\Pinyin;
|
||||
|
||||
class City extends BaseController
|
||||
{
|
||||
@ -49,6 +50,154 @@ class City extends BaseController
|
||||
return app('json')->success(app()->make(CityAreaRepository::class)->getChildren(intval($pid)));
|
||||
}
|
||||
|
||||
public function lstV3()
|
||||
{
|
||||
$provinceCode = $this->request->param('province_code') ?? '';
|
||||
$cityCode = $this->request->param('city_code') ?? '';
|
||||
$areaCode = $this->request->param('area_code') ?? '';
|
||||
$streetCode = $this->request->param('street_code') ?? '';
|
||||
$pinyin = $this->request->param('pinyin') ?? 0;
|
||||
$list = app()->make(CityAreaRepository::class)->getGeoChildren(['province_code' => $provinceCode, 'city_code' => $cityCode, 'area_code' => $areaCode, 'street_code' => $streetCode]);
|
||||
$geoList = [];
|
||||
$pyList = [];
|
||||
foreach ($list as $v) {
|
||||
$temp = [];
|
||||
if (!empty($v['village_id'])) {
|
||||
if ($pinyin == 1) {
|
||||
$py = strtoupper((new Pinyin)->abbr($v['village_name'])[0] ?? '-');
|
||||
$pyList[$py][] = [
|
||||
'type' => 'village',
|
||||
'id' => $v['village_id'],
|
||||
'level' => 5,
|
||||
'name' => $v['village_name'] ?? '',
|
||||
'code' => $v['village_code'] ?? ''
|
||||
];
|
||||
} else {
|
||||
$temp = [
|
||||
'type' => 'village',
|
||||
'id' => $v['village_id'],
|
||||
'level' => 5,
|
||||
'name' => $v['village_name'] ?? '',
|
||||
'code' => $v['village_code'] ?? ''
|
||||
];
|
||||
$geoList[] = $temp;
|
||||
}
|
||||
}
|
||||
if (!empty($v['street_id'])) {
|
||||
if ($pinyin == 1) {
|
||||
$py = strtoupper((new Pinyin)->abbr($v['street_name'])[0] ?? '-');
|
||||
$pyList[$py][] = [
|
||||
'type' => 'street',
|
||||
'id' => $v['street_id'],
|
||||
'level' => 4,
|
||||
'name' => $v['street_name'] ?? '',
|
||||
'code' => $v['street_code'] ?? ''
|
||||
];
|
||||
} else {
|
||||
$temp = [
|
||||
'type' => 'street',
|
||||
'id' => $v['street_id'],
|
||||
'level' => 4,
|
||||
'name' => $v['street_name'] ?? '',
|
||||
'code' => $v['street_code'] ?? ''
|
||||
];
|
||||
$geoList[] = $temp;
|
||||
}
|
||||
}
|
||||
if (!empty($v['area_id'])) {
|
||||
if ($pinyin == 1) {
|
||||
$py = strtoupper((new Pinyin)->abbr($v['area_name'])[0] ?? '-');
|
||||
$pyList[$py][] = [
|
||||
'type' => 'area',
|
||||
'id' => $v['area_id'],
|
||||
'level' => 3,
|
||||
'name' => $v['area_name'] ?? '',
|
||||
'code' => $v['area_code'] ?? ''
|
||||
];
|
||||
} else {
|
||||
$temp = [
|
||||
'type' => 'area',
|
||||
'id' => $v['area_id'],
|
||||
'level' => 3,
|
||||
'name' => $v['area_name'] ?? '',
|
||||
'code' => $v['area_code'] ?? ''
|
||||
];
|
||||
$geoList[] = $temp;
|
||||
}
|
||||
}
|
||||
if (!empty($v['city_id'])) {
|
||||
if ($pinyin == 1) {
|
||||
$py = strtoupper((new Pinyin)->abbr($v['city_name'])[0] ?? '-');
|
||||
$pyList[$py][] = [
|
||||
'type' => 'city',
|
||||
'id' => $v['city_id'],
|
||||
'level' => 2,
|
||||
'name' => $v['city_name'] ?? '',
|
||||
'code' => $v['city_code'] ?? ''
|
||||
];
|
||||
} else {
|
||||
$temp = [
|
||||
'type' => 'city',
|
||||
'id' => $v['city_id'],
|
||||
'level' => 2,
|
||||
'name' => $v['city_name'] ?? '',
|
||||
'code' => $v['city_code'] ?? '',
|
||||
];
|
||||
$geoList[] = $temp;
|
||||
}
|
||||
}
|
||||
if (!empty($v['province_id'])) {
|
||||
if ($pinyin == 1) {
|
||||
$py = strtoupper((new Pinyin)->abbr($v['province_name'])[0] ?? '-');
|
||||
$pyList[$py][] = [
|
||||
'type' => 'province',
|
||||
'id' => $v['province_id'],
|
||||
'level' => 1,
|
||||
'name' => $v['province_name'] ?? '',
|
||||
'code' => $v['province_code'] ?? ''
|
||||
];
|
||||
} else {
|
||||
$temp = [
|
||||
'type' => 'province',
|
||||
'id' => $v['province_id'],
|
||||
'level' => 1,
|
||||
'name' => $v['province_name'] ?? '',
|
||||
'code' => $v['province_code'] ?? ''
|
||||
];
|
||||
$geoList[] = $temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($pinyin == 1) {
|
||||
$geoList = [];
|
||||
foreach($pyList as $k=>$v) {
|
||||
$temp = [];
|
||||
$temp['pinyin'] = $k;
|
||||
$temp['data'] = $pyList[$k];
|
||||
$geoList[] = $temp;
|
||||
}
|
||||
}
|
||||
return app('json')->success($geoList);
|
||||
}
|
||||
|
||||
public function brigade()
|
||||
{
|
||||
$list = app()->make(CityAreaRepository::class)->getBrigade([]);
|
||||
$geoList = [];
|
||||
foreach ($list as $v) {
|
||||
$temp = [
|
||||
'type' => 'brigade',
|
||||
'id' => $v['id'],
|
||||
'level' => 6,
|
||||
'name' => $v['brigade_name'] ?? '',
|
||||
'code' => $v['brigade_name'] ?? ''
|
||||
];
|
||||
$geoList[] = $temp;
|
||||
}
|
||||
return app('json')->success($geoList);
|
||||
}
|
||||
|
||||
|
||||
public function cityList()
|
||||
{
|
||||
$address = $this->request->param('address');
|
||||
|
@ -87,6 +87,9 @@ class Merchant extends BaseController
|
||||
'long',
|
||||
'lat',
|
||||
['delivery_way',[2]],
|
||||
'credit_buy',
|
||||
'settle_cycle',
|
||||
'interest_rate',
|
||||
]);
|
||||
$validate->check($data);
|
||||
$sys_bases_status = systemConfig('sys_bases_status') === '0' ? 0 : 1;
|
||||
|
@ -55,18 +55,24 @@ return [
|
||||
\crmeb\listens\AuthCancelActivityListen::class,
|
||||
\crmeb\listens\CloseUserSvipListen::class,
|
||||
\crmeb\listens\SendSvipCouponListen::class,
|
||||
\crmeb\listens\AutoCheckCreditBuyListen::class,
|
||||
] : [],
|
||||
'pay_success_user_recharge' => [\crmeb\listens\pay\UserRechargeSuccessListen::class],
|
||||
'pay_success_user_order' => [\crmeb\listens\pay\UserOrderSuccessListen::class],
|
||||
'pay_success_order' => [\crmeb\listens\pay\OrderPaySuccessListen::class],
|
||||
'pay_success_order_settle' => [\crmeb\listens\pay\OrderSettlePaySuccessListen::class],
|
||||
'pay_success_micro_pay' => [\crmeb\listens\pay\OrderMicroPaySuccessListen::class],
|
||||
'pay_success_presell' => [\crmeb\listens\pay\PresellPaySuccessListen::class],
|
||||
'pay_success_meal' => [\crmeb\listens\pay\MealSuccessListen::class],
|
||||
// 'community_address'=>[\app\listener\CommunityAddress::class],
|
||||
'order.paySuccessOrder'=>[\app\listener\paySuccessOrder::class],
|
||||
'order.sendGoodsCode'=>[\app\listener\SendGoodsCode::class],
|
||||
'product.create'=>[\app\listener\ProductCreate::class],
|
||||
'product.delivery'=>[\app\listener\DeliveryGoods::class],
|
||||
'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架
|
||||
'refund.after'=>[\app\listener\AfterRefund::class],
|
||||
'refund.deliver'=>[\app\listener\DeliverRefund::class],
|
||||
'order.create'=>[\app\listener\OrderCreate::class],
|
||||
],
|
||||
|
||||
'subscribe' => [],
|
||||
|
45
app/listener/DeliverRefund.php
Normal file
45
app/listener/DeliverRefund.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\listener;
|
||||
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 订单退款通知物流
|
||||
*/
|
||||
class DeliverRefund
|
||||
{
|
||||
public function handle($event)
|
||||
{
|
||||
$orderId = $event['refund']['order']['order_id'] ?? 0;
|
||||
$orderSn = $event['refund']['order']['order_sn'] ?? '';
|
||||
Log::info('物流退货 - orderId:' . $orderId . ' orderSn:' . $orderSn);
|
||||
if ($orderId && $orderSn) {
|
||||
Db::name('product_order_log')->where('order_id', $orderId)->update(['status' => 2]);
|
||||
$this->sendLogistics($orderId, $orderSn);
|
||||
}
|
||||
}
|
||||
|
||||
//发送物流
|
||||
public function sendLogistics($orderId, $orderSn)
|
||||
{
|
||||
Log::info("发送物流退货信息 orderId: {$orderId}, orderSn: {$orderSn}");
|
||||
$postUrl = env('LOGISTICS_HOST_URL') . '/api/cancelOrder';
|
||||
$curlPost = [
|
||||
'order_id' => $orderId,
|
||||
'order_sn' => $orderSn,
|
||||
];
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $postUrl);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
||||
$data = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
Log::info("物流退货信息" . $data);
|
||||
}
|
||||
}
|
67
app/listener/DeliveryGoods.php
Normal file
67
app/listener/DeliveryGoods.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\listener;
|
||||
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\model\store\order\StoreOrder;
|
||||
use crmeb\services\SmsService;
|
||||
use crmeb\utils\DingTalk;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class DeliveryGoods
|
||||
{
|
||||
public $event;
|
||||
|
||||
public function handle($event)
|
||||
{
|
||||
$this->event = $event;
|
||||
Log::info("delivery ============= handle监听order_id " . $this->event['order']['order_id']);
|
||||
$this->event = $event;
|
||||
//发生短信包含收货码
|
||||
$this->sendLogisticsCode($this->event['order']['uid'], $this->event['order']['order_id'], $this->event['order']['order_sn']);
|
||||
}
|
||||
|
||||
public function sendLogisticsCode($uid, $orderId, $orderSn) {
|
||||
//收货人短信
|
||||
$phone = StoreOrder::where('order_id', $orderId)->value('user_phone');
|
||||
$realName = StoreOrder::where('order_id', $orderId)->value('real_name');
|
||||
if ($realName) {
|
||||
$realName = $this->hidestr($realName, 1, 0);
|
||||
} else {
|
||||
$realName = '**';
|
||||
}
|
||||
$logisticsCode = StoreOrder::where('order_id', $orderId)->value('logistics_code');
|
||||
$logisticsPhone = StoreOrder::where('order_id', $orderId)->value('logistics_phone');
|
||||
if ($phone) {
|
||||
Log::info("发送短信 {$phone}, orderId: {$orderId}");
|
||||
SmsService::create()->send($phone, 'PICKUP_CODE', ['name' => $realName, 'number' => substr($orderSn, -6), 'number2' => $logisticsCode, 'phone' => $logisticsPhone ?? '']);
|
||||
}
|
||||
}
|
||||
|
||||
public function hidestr($string, $start = 0, $length = 0, $re = '*') {
|
||||
if (empty($string)) return false;
|
||||
$strarr = array();
|
||||
$mb_strlen = mb_strlen($string);
|
||||
while ($mb_strlen) {
|
||||
$strarr[] = mb_substr($string, 0, 1, 'utf8');
|
||||
$string = mb_substr($string, 1, $mb_strlen, 'utf8');
|
||||
$mb_strlen = mb_strlen($string);
|
||||
}
|
||||
$strlen = count($strarr);
|
||||
$begin = $start >= 0 ? $start : ($strlen - abs($start));
|
||||
$end = $last = $strlen - 1;
|
||||
if ($length > 0) {
|
||||
$end = $begin + $length - 1;
|
||||
} elseif ($length < 0) {
|
||||
$end -= abs($length);
|
||||
}
|
||||
for ($i=$begin; $i<=$end; $i++) {
|
||||
$strarr[$i] = $re;
|
||||
}
|
||||
if ($begin > $end || $begin > $last || $end > $last) return '';
|
||||
return implode('', $strarr);
|
||||
}
|
||||
|
||||
}
|
39
app/listener/OrderCreate.php
Normal file
39
app/listener/OrderCreate.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\listener;
|
||||
|
||||
use app\common\model\store\order\StoreGroupOrder;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\store\order\StoreOrderInterestRepository;
|
||||
|
||||
/**
|
||||
* 下单后置事件
|
||||
*/
|
||||
class OrderCreate
|
||||
{
|
||||
|
||||
public function handle($event)
|
||||
{
|
||||
$groupOrder = $event['groupOrder'];
|
||||
$order = $groupOrder->orderList[0];
|
||||
if ($order['pay_type'] != StoreGroupOrder::PAY_TYPE_CREDIT_BUY || $order['activity_type'] != 98) {
|
||||
return true;
|
||||
}
|
||||
/** @var StoreOrderInterestRepository $storeOrderInterestRepository */
|
||||
$storeOrderInterestRepository = app()->make(StoreOrderInterestRepository::class);
|
||||
$merchantId = Merchant::where('uid', $groupOrder['uid'])->value('mer_id');
|
||||
$data = [
|
||||
'group_order_id' => $groupOrder['group_order_id'],
|
||||
'order_id' => $order['order_id'] ?? 0,
|
||||
'mer_id' => $merchantId,
|
||||
'to_mer_id' => $order['mer_id'] ?? 0,
|
||||
'total_price' => $groupOrder['total_price'],
|
||||
'rate' => $order['merchant']['interest_rate'] ?? 0,
|
||||
'settle_cycle' => $order['merchant']['settle_cycle'] ?? 0,
|
||||
];
|
||||
return $storeOrderInterestRepository->create($data);
|
||||
}
|
||||
|
||||
}
|
100
app/listener/SendGoodsCode.php
Normal file
100
app/listener/SendGoodsCode.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\listener;
|
||||
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use crmeb\utils\DingTalk;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class SendGoodsCode
|
||||
{
|
||||
public $event;
|
||||
|
||||
public function handle($event)
|
||||
{
|
||||
$this->event = $event;
|
||||
Log::info("sendGoodsCode ============= handle监听order_id " . $this->event['order_id']);
|
||||
if ($this->event['activity_type'] == 0) {
|
||||
//发起物流信息返回快递员手机
|
||||
$logisticsPhone = $this->sendLogistics($this->event['order_id'], $this->event['order_sn']);
|
||||
//生成用户的收货码
|
||||
$this->generateLogisticsCode($this->event['uid'], $this->event['order_id'], $this->event['order_sn'], $logisticsPhone);
|
||||
//记录订单收货地址记录
|
||||
$this->recordOrderAddr($this->event);
|
||||
}
|
||||
}
|
||||
|
||||
//订单收货记录
|
||||
public function recordOrderAddr($order) {
|
||||
//province_code . city_code . district_code . street_code . village_code . brigade_id;
|
||||
//设置地址信息
|
||||
$addressInfo = explode(',', $order['user_address_code'] ?? '');
|
||||
$productOrder = [
|
||||
'uid' => $order['uid'] ?? 0,
|
||||
'order_id' => $order['order_id'] ?? 0,
|
||||
'province_code' => $addressInfo[0] ?? '',
|
||||
'city_code' => $addressInfo[1] ?? '',
|
||||
'district_code' => $addressInfo[2] ?? '',
|
||||
'street_code' => $addressInfo[3] ?? '',
|
||||
'village_code' => $addressInfo[4] ?? '',
|
||||
'brigade_id' => $addressInfo[5] ?? 0,
|
||||
'status' => 1,
|
||||
'create_time' => date('Y-m-d H:i:s')
|
||||
];
|
||||
//商品信息
|
||||
$productInfo = Db::name('store_order_product')->where('order_id', $order['order_id'] ?? 0)->find();
|
||||
if ($productInfo) {
|
||||
$productOrder['product_id'] = $productInfo['product_id'] ?? 0;
|
||||
$productOrder['product_price'] = $productInfo['product_price'] ?? 0;
|
||||
$productOrder['total_price'] = $productInfo['total_price'] ?? 0;
|
||||
$productOrder['product_num'] = $productInfo['product_num'] ?? 0;
|
||||
}
|
||||
//商户信息
|
||||
$merchantInfo = Db::name('merchant')->where('mer_id', $order['mer_id'] ?? 0)->find();
|
||||
if ($merchantInfo) {
|
||||
$productOrder['mer_id'] = $merchantInfo['mer_id'] ?? 0;
|
||||
$productOrder['mer_category_id'] = $merchantInfo['category_id'] ?? 0;
|
||||
$productOrder['mer_type_id'] = $merchantInfo['type_id'] ?? 0;
|
||||
$productOrder['is_trader'] = $merchantInfo['is_trader'] ?? 0;
|
||||
}
|
||||
Db::name('ProductOrderLog')->insert($productOrder);
|
||||
}
|
||||
|
||||
//用户收货码
|
||||
public function generateLogisticsCode($uid, $orderId, $orderSn, $logisticsPhone) {
|
||||
$code = random_int(1000, 9999);
|
||||
app()->make(StoreOrderRepository::class)->update($orderId, [
|
||||
'logistics_code' => $code,
|
||||
'logistics_phone' => $logisticsPhone
|
||||
]);
|
||||
}
|
||||
|
||||
//发送物流
|
||||
public function sendLogistics($orderId, $orderSn)
|
||||
{
|
||||
Log::info("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}");
|
||||
$postUrl = env('LOGISTICS_HOST_URL') . '/api/lstSet';
|
||||
$curlPost = [
|
||||
'order_id' => $orderId,
|
||||
'order_sn' => $orderSn,
|
||||
];
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $postUrl);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
||||
$data = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$phone = '';
|
||||
if (!empty($data) && is_string($data)) {
|
||||
$logisticsInfo = json_decode($data, true);
|
||||
$phone = $logisticsInfo['data']['phone'] ?? '';
|
||||
Log::info("物流联系信息" . json_encode($logisticsInfo));
|
||||
}
|
||||
return $phone;
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ namespace app\listener;
|
||||
use app\common\dao\store\order\StoreCartDao;
|
||||
use app\common\dao\system\merchant\MerchantDao;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\system\merchant\FinancialRecordRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use crmeb\utils\DingTalk;
|
||||
@ -123,7 +124,7 @@ class paySuccessOrder
|
||||
];
|
||||
}
|
||||
|
||||
if (!$financialRecordRepository->insertAll($this->finance)) {
|
||||
if ($financialRecordRepository->insertAll($this->finance) === false) {
|
||||
throw new \Exception('财务流水保存出错');
|
||||
}
|
||||
Db::commit();
|
||||
|
@ -29,6 +29,8 @@ class MerchantUpdateValidate extends Validate
|
||||
'mer_address|店铺地址' => 'require|max:128',
|
||||
'long|店铺经度' => 'max:24',
|
||||
'lat|店铺纬度' => 'max:24',
|
||||
'interest_rate|利率' => 'egt:0.01|elt:0.1',
|
||||
'settle_cycle|结算周期' => 'egt:15|elt:90',
|
||||
];
|
||||
|
||||
protected function isPhone($val)
|
||||
|
@ -55,7 +55,9 @@
|
||||
"swoole/ide-helper": "^4.8",
|
||||
"alibabacloud/dysmsapi-20170525": "2.0.9",
|
||||
"fastknife/ajcaptcha": "^1.1",
|
||||
"vlucas/phpdotenv": "^5.3"
|
||||
"vlucas/phpdotenv": "^5.3",
|
||||
"overtrue/pinyin": "4.1.0",
|
||||
"jpush/jpush": "^3.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^4.2",
|
||||
|
122
composer.lock
generated
122
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "cdcb3c1e7a4e523b77afdea055928bd4",
|
||||
"content-hash": "2e5b7298b7a4853ac416129d0c04cb79",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adbario/php-dot-notation",
|
||||
@ -1613,6 +1613,53 @@
|
||||
],
|
||||
"time": "2020-11-26T13:13:58+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jpush/jpush",
|
||||
"version": "v3.6.8",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jpush/jpush-api-php-client.git",
|
||||
"reference": "ebb191e8854a35c3fb7a6626028b3a23132cbe2c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/jpush/jpush-api-php-client/zipball/ebb191e8854a35c3fb7a6626028b3a23132cbe2c",
|
||||
"reference": "ebb191e8854a35c3fb7a6626028b3a23132cbe2c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"JPush\\": "src/JPush/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "JPush",
|
||||
"email": "support@jpush.cn",
|
||||
"homepage": "https://www.jpush.cn/",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "JPush API PHP Client",
|
||||
"homepage": "https://github.com/jpush/jpush-api-php-client",
|
||||
"support": {
|
||||
"issues": "https://github.com/jpush/jpush-api-php-client/issues",
|
||||
"source": "https://github.com/jpush/jpush-api-php-client/tree/v3.6.8"
|
||||
},
|
||||
"time": "2021-08-12T07:43:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "khanamiryan/qrcode-detector-decoder",
|
||||
"version": "1.0.3",
|
||||
@ -2628,6 +2675,79 @@
|
||||
],
|
||||
"time": "2020-05-29T05:20:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "overtrue/pinyin",
|
||||
"version": "4.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/overtrue/pinyin.git",
|
||||
"reference": "4d0fb4f27f0c79e81c9489e0c0ae4a4f8837eae7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/overtrue/pinyin/zipball/4d0fb4f27f0c79e81c9489e0c0ae4a4f8837eae7",
|
||||
"reference": "4d0fb4f27f0c79e81c9489e0c0ae4a4f8837eae7",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"brainmaestro/composer-git-hooks": "^2.7",
|
||||
"friendsofphp/php-cs-fixer": "^2.16",
|
||||
"phpunit/phpunit": "~8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"hooks": {
|
||||
"pre-commit": [
|
||||
"composer test",
|
||||
"composer fix-style"
|
||||
],
|
||||
"pre-push": [
|
||||
"composer test",
|
||||
"composer check-style"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/const.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Overtrue\\Pinyin\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "overtrue",
|
||||
"email": "anzhengchao@gmail.com",
|
||||
"homepage": "http://github.com/overtrue"
|
||||
}
|
||||
],
|
||||
"description": "Chinese to pinyin translator.",
|
||||
"homepage": "https://github.com/overtrue/pinyin",
|
||||
"keywords": [
|
||||
"Chinese",
|
||||
"Pinyin",
|
||||
"cn2pinyin"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/overtrue/pinyin/issues",
|
||||
"source": "https://github.com/overtrue/pinyin/tree/4.1.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/overtrue",
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2023-04-27T10:17:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "overtrue/socialite",
|
||||
"version": "1.3.0",
|
||||
|
@ -17,7 +17,7 @@ use think\swoole\websocket\socketio\Parser;
|
||||
return [
|
||||
'server' => [
|
||||
'host' => env('SWOOLE_HOST', '0.0.0.0'), // 监听地址
|
||||
'port' => env('SWOOLE_PORT', 8324), // 监听端口
|
||||
'port' => env('SWOOLE_PORT', 8325), // 监听端口
|
||||
'mode' => SWOOLE_PROCESS, // 运行模式 默认为SWOOLE_PROCESS
|
||||
'sock_type' => SWOOLE_SOCK_TCP, // sock type 默认为SWOOLE_SOCK_TCP
|
||||
'options' => [
|
||||
|
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace crmeb\jobs;
|
||||
|
||||
|
||||
use app\common\dao\system\serve\ServeOrderDao;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use app\common\repositories\system\serve\ServeOrderRepository;
|
||||
use crmeb\interfaces\JobInterface;
|
||||
use think\facade\Log;
|
||||
|
||||
class AutoMarginJob implements JobInterface
|
||||
{
|
||||
|
||||
public function fire($job, $data)
|
||||
{
|
||||
Log::info('utoMarginStart:' . var_export($data, 1));
|
||||
try {
|
||||
$merchant = app()->make(MerchantRepository::class)->get($data['merId']);
|
||||
$orderInfo = [
|
||||
'type_id' => $merchant['type_id'],
|
||||
'is_margin' => $merchant['is_margin'],
|
||||
'margin' => $data['margin'],
|
||||
];
|
||||
$values = [
|
||||
'status' => 1,
|
||||
'is_del' => 0,
|
||||
'mer_id' => $merchant['mer_id'],
|
||||
'type' => ServeOrderRepository::TYPE_MARGIN,
|
||||
'meal_id'=> $merchant['type_id'],
|
||||
'pay_type' => ServeOrderRepository::PAY_TYPE_BALANCE,
|
||||
'order_info' => json_encode($orderInfo,JSON_UNESCAPED_UNICODE),
|
||||
'pay_price' => $data['margin'],
|
||||
'store_order_id' => $data['orderId'],
|
||||
];
|
||||
$values['order_sn'] = app()->make(StoreOrderRepository::class)->getNewOrderId('cs');
|
||||
$values['pay_time'] = date('y_m-d H:i:s', time());
|
||||
if (!app()->make(ServeOrderDao::class)->create($values)) {
|
||||
throw new \Exception('serve_order 保存出错');
|
||||
}
|
||||
$merchant->paid_margin = bcadd($data['margin'], $merchant->paid_margin, 2);
|
||||
$merchant->ot_margin = $merchant->paid_margin;
|
||||
$merchant->is_margin = MerchantRepository::PaidMargin;
|
||||
$merchant->save();
|
||||
$job->delete();
|
||||
} catch (\Exception $exception) {
|
||||
Log::info('更新商户保证金出错:' . var_export($exception, 1));
|
||||
} finally {
|
||||
Log::info('autoMarginEnd:' . var_export($data, 1));
|
||||
}
|
||||
}
|
||||
|
||||
public function failed($data)
|
||||
{
|
||||
// TODO: Implement failed() method.
|
||||
}
|
||||
}
|
@ -15,9 +15,11 @@ namespace crmeb\jobs;
|
||||
|
||||
|
||||
use app\common\repositories\system\notice\SystemNoticeConfigRepository;
|
||||
use app\common\service\JgPush;
|
||||
use crmeb\interfaces\JobInterface;
|
||||
use crmeb\services\SmsService;
|
||||
use crmeb\services\WechatTemplateMessageService;
|
||||
use crmeb\utils\DingTalk;
|
||||
use think\facade\Log;
|
||||
|
||||
class SendSmsJob implements JobInterface
|
||||
@ -26,6 +28,20 @@ class SendSmsJob implements JobInterface
|
||||
public function fire($job, $data)
|
||||
{
|
||||
$status = app()->make(SystemNoticeConfigRepository::class)->getNoticeStatusByConstKey($data['tempId']);
|
||||
if (!$status) {
|
||||
$job->delete();
|
||||
}
|
||||
if ($status['notice_app'] == 1) {
|
||||
try {
|
||||
/** @var JgPush $client */
|
||||
$client = app()->make(JgPush::class);
|
||||
Log::info('app推送发送数据:' . var_export($data, 1));
|
||||
$client->send($data['tempId'], $data);
|
||||
} catch (\Exception $e) {
|
||||
Log::info('app推送消息发送失败' . var_export($data, 1) . $e->getMessage());
|
||||
DingTalk::exception($e, 'app推送消息发送失败' . var_export($data, 1));
|
||||
}
|
||||
}
|
||||
if ($status['notice_sms'] == 1) {
|
||||
try {
|
||||
SmsService::sendMessage($data);
|
||||
|
29
crmeb/listens/AutoCheckCreditBuyListen.php
Normal file
29
crmeb/listens/AutoCheckCreditBuyListen.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace crmeb\listens;
|
||||
|
||||
use app\common\model\store\order\StoreOrderInterest;
|
||||
use crmeb\interfaces\ListenerInterface;
|
||||
use crmeb\jobs\SendSmsJob;
|
||||
use crmeb\services\TimerService;
|
||||
use think\facade\Log;
|
||||
use think\facade\Queue;
|
||||
|
||||
class AutoCheckCreditBuyListen extends TimerService implements ListenerInterface
|
||||
{
|
||||
public function handle($event): void
|
||||
{
|
||||
Log::info('credit buy listen start');
|
||||
$tomorrow = strtotime('tomorrow 15:00:00');
|
||||
$time = ($tomorrow - time()) * 1000;
|
||||
$this->tick($time, function () {
|
||||
request()->clearCache();
|
||||
$time = strtotime('+3 days');
|
||||
$unSettle = StoreOrderInterest::whereBetweenTime('start_time', time(), $time)->where('status', 0)->group('mer_id')->column('order_id,mer_id');
|
||||
foreach ($unSettle as $item) {
|
||||
Log::info('credit buy listen push job');
|
||||
Queue::push(SendSmsJob::class, ['tempId' => 'MERCHANT_CREDIT_BUY_NOTICE', 'id' => $item['mer_id'], 'orderId' => $item['order_id']]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
59
crmeb/listens/pay/OrderSettlePaySuccessListen.php
Normal file
59
crmeb/listens/pay/OrderSettlePaySuccessListen.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace crmeb\listens\pay;
|
||||
|
||||
|
||||
use app\common\model\store\order\StoreOrderInterest;
|
||||
use app\common\repositories\store\order\StoreGroupOrderRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use crmeb\interfaces\ListenerInterface;
|
||||
use crmeb\utils\DingTalk;
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class OrderSettlePaySuccessListen implements ListenerInterface
|
||||
{
|
||||
|
||||
public function handle($data): void
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$orderSn = $data['order_sn'];
|
||||
$groupOrder = app()->make(StoreGroupOrderRepository::class)->getWhere(['group_order_sn' => $orderSn]);
|
||||
if (!$groupOrder || !$groupOrder->interest || $groupOrder->interest->status == StoreOrderInterest::STATUS_SETTLED) {
|
||||
throw new \Exception('订单无需结算');
|
||||
}
|
||||
|
||||
/** @var StoreOrderRepository $storeOrderRepo */
|
||||
$storeOrderRepo = app()->make(StoreOrderRepository::class);
|
||||
$storeOrderRepo->paySuccess($groupOrder);
|
||||
|
||||
app()->make(MerchantRepository::class)->computedLockMoney($groupOrder->order);
|
||||
$groupOrder->interest->status = StoreOrderInterest::STATUS_SETTLED;
|
||||
$groupOrder->interest->settle_time = date('Y-m-d H:i:s');
|
||||
if (!$groupOrder->interest->save()) {
|
||||
throw new \Exception('订单结算信息保存失败');
|
||||
}
|
||||
//订单结算之后,修改订单支付方式为真实的支付方式
|
||||
$groupOrder->pay_type = 1;
|
||||
$groupOrder->save();
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
Log::error($e->getMessage(), $data);
|
||||
DingTalk::exception($e, $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -322,7 +322,7 @@ class MiniProgramService
|
||||
public function refund($orderNo, $refundNo, $totalFee, $refundFee = null, $opUserId = null, $refundReason = '', $type = 'out_trade_no', $refundAccount = 'REFUND_SOURCE_UNSETTLED_FUNDS',$openId = null, $transactionId = null)
|
||||
{
|
||||
if (empty($this->config['payment']['pay_routine_client_key']) || empty($this->config['payment']['pay_routine_client_cert'])) {
|
||||
throw new \Exception('请配置微信支付证书');
|
||||
throw new \Exception('请配置微信支付证书', 500);
|
||||
}
|
||||
$totalFee = floatval($totalFee);
|
||||
$refundFee = floatval($refundFee);
|
||||
|
@ -282,6 +282,9 @@ class SmsService
|
||||
case 'SVIP_PAY_SUCCESS':
|
||||
self::create()->send($id['phone'], $tempId, ['store_name' => systemConfig('site_name'),'date' => $id['date']]);
|
||||
break;
|
||||
case 'MERCHANT_CREDIT_BUY_NOTICE':
|
||||
self::sendMerMessage($id, $tempId, ['order_id' => $data['orderId']]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,7 +520,7 @@ class WechatService
|
||||
public function refund($orderNo, $refundNo, $totalFee, $refundFee = null, $opUserId = null, $refundReason = '', $type = 'out_trade_no', $refundAccount = 'REFUND_SOURCE_UNSETTLED_FUNDS')
|
||||
{
|
||||
if (empty($this->config['payment']['pay_weixin_client_cert']) || empty($this->config['payment']['pay_weixin_client_key'])) {
|
||||
throw new \Exception('请配置微信支付证书');
|
||||
throw new \Exception('请配置微信支付证书', 500);
|
||||
}
|
||||
$totalFee = floatval($totalFee);
|
||||
$refundFee = floatval($refundFee);
|
||||
|
82
crmeb/services/payTool/Balance.php
Normal file
82
crmeb/services/payTool/Balance.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace crmeb\services\payTool;
|
||||
|
||||
class Balance extends PayTool
|
||||
{
|
||||
|
||||
public $order;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付
|
||||
* @param $order
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function pay($order)
|
||||
{
|
||||
$user = request()->userInfo();
|
||||
if (!systemConfig('yue_pay_status')) {
|
||||
throw new \Exception('未开启余额支付');
|
||||
}
|
||||
if ($user['now_money'] < $order['pay_price']) {
|
||||
throw new \Exception('余额不足,请更换支付方式');
|
||||
}
|
||||
$user->now_money = bcsub($user->now_money, $order['pay_price'], 2);
|
||||
if (!$user->save()) {
|
||||
throw new \Exception('用户余额扣减失败', 500);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
* @param $order
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function query($order)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款
|
||||
* @param $order
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function refund($order)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起请求
|
||||
* @param $body
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function request($body)
|
||||
{
|
||||
}
|
||||
|
||||
public function success()
|
||||
{
|
||||
}
|
||||
|
||||
public function callback($request = null)
|
||||
{
|
||||
}
|
||||
|
||||
public function refundQuery($refundOrder)
|
||||
{
|
||||
}
|
||||
|
||||
public function transfer($withdraw)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
@ -7,21 +7,16 @@ abstract class PayTool
|
||||
|
||||
public $config;
|
||||
public $error = ['success' => false];
|
||||
const Scrcu = 'scrcu';
|
||||
|
||||
const ClassMap = [
|
||||
self::Scrcu => Scrcu::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $params
|
||||
* @return mixed|Scrcu
|
||||
* @return mixed|PayTool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function instance($name, $params = [])
|
||||
{
|
||||
$class = self::ClassMap[$name];
|
||||
$class = 'crmeb\services\payTool\\' . ucfirst($name);
|
||||
if (class_exists($class)) {
|
||||
return new $class($params);
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class Scrcu extends PayTool
|
||||
$order['subject'] = $firstGoods->product->store_name . " 等{$order['total_num']}件商品";
|
||||
return $order;
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception('商品信息错误');
|
||||
throw new \Exception('商品信息错误', 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
.selWidth[data-v-7d1aafac]{width:320px}
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
.selWidth[data-v-12ad4e01]{width:300px}
|
@ -1 +0,0 @@
|
||||
.box-container[data-v-ff040404]{overflow:hidden}.box-container .list[data-v-ff040404]{float:left;line-height:40px}.box-container .sp[data-v-ff040404]{width:50%}.box-container .sp3[data-v-ff040404]{width:33.3333%}.box-container .sp100[data-v-ff040404]{width:100%}.box-container .list .name[data-v-ff040404]{display:inline-block;width:150px;text-align:right;color:#606266}.box-container .list .blue[data-v-ff040404]{color:#1890ff}.box-container .list.image[data-v-ff040404]{margin-bottom:40px}.box-container .list.image img[data-v-ff040404]{position:relative;top:40px}.el-textarea[data-v-ff040404]{width:400px}[data-v-ff040404] .el-input__inner{padding-right:0}.modalbox[data-v-39dfaaaa] .el-dialog{min-width:550px}.selWidth[data-v-39dfaaaa]{width:400px}.seachTiele[data-v-39dfaaaa]{line-height:35px}.fa[data-v-39dfaaaa]{color:#0a6aa1;display:block}.sheng[data-v-39dfaaaa]{color:red;display:block}
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
.projectInfo[data-v-1e82037e] .el-dialog__body{padding-top:0!important}.projectInfo[data-v-1e82037e] .el-tabs__content{padding-left:10px!important}.tabPic[data-v-1e82037e]{width:40px!important;height:40px!important}.tabPic img[data-v-1e82037e]{width:100%;height:100%}.sp[data-v-1e82037e]{display:block;width:33%;font-size:12px;margin-bottom:20px}.sp100[data-v-1e82037e]{width:100%;margin-bottom:15px;display:inline-block}.third[data-v-1e82037e]{width:100%;display:-webkit-box;display:-ms-flexbox;display:flex}.pictrue[data-v-1e82037e]{width:60px;height:60px;border:1px dotted rgba(0,0,0,.1);margin-right:10px;position:relative;cursor:pointer;display:inline-block}.pictrue img[data-v-1e82037e]{width:100%;height:100%}.demo-image__preview[data-v-1e82037e]{display:inline-block}[data-v-006583a9] .el-select-dropdown__item{max-width:350px!important}.template[data-v-006583a9]{overflow:hidden}.label-list[data-v-006583a9]{height:100%}.bg[data-v-006583a9]{z-index:100;position:fixed;left:0;top:0;width:100%;height:100%;background:rgba(0,0,0,.5)}.rate_star[data-v-006583a9]{position:relative;top:5px}table .el-image[data-v-006583a9]{display:inline-block}.demo-table-expand[data-v-006583a9]{font-size:0}.demo-table-expand[data-v-006583a9] label{width:105px;color:#99a9bf}.demo-table-expand .el-form-item[data-v-006583a9]{margin-right:0;margin-bottom:0;width:33.33%}.selWidth[data-v-006583a9]{width:350px!important}.seachTiele[data-v-006583a9]{line-height:35px}
|
@ -1 +0,0 @@
|
||||
.card_container[data-v-d21d1c7c]{margin-top:150px;text-align:center}
|
@ -1 +0,0 @@
|
||||
[data-v-8765f0e4] .el-dialog{margin-top:0!important;width:840px}.mer_phone[data-v-8765f0e4]{width:400px}.dis[data-v-8765f0e4],.switch_btn[data-v-8765f0e4]{display:-webkit-box;display:-ms-flexbox;display:flex}.switch_btn[data-v-8765f0e4]{-ms-flex-wrap:wrap;flex-wrap:wrap}.switch_btn .mini_btn[data-v-8765f0e4]{width:390px!important}
|
@ -1 +0,0 @@
|
||||
.rate_star[data-v-f56ae7fe]{display:inline-block}.box-container[data-v-f56ae7fe]{overflow:hidden}.box-container .list[data-v-f56ae7fe]{float:left;line-height:40px}.box-container .sp[data-v-f56ae7fe]{width:50%}.box-container .sp3[data-v-f56ae7fe]{width:33.3333%}.box-container .sp100[data-v-f56ae7fe]{width:100%}.box-container .list .name[data-v-f56ae7fe]{display:inline-block;width:150px;text-align:right;color:#606266}.box-container .list .blue[data-v-f56ae7fe]{color:#1890ff}.box-container .list.image[data-v-f56ae7fe]{margin-bottom:40px}.box-container .list.image img[data-v-f56ae7fe]{position:relative;top:40px}[data-v-f56ae7fe] .el-input__inner{padding-right:0}.copyBtn[data-v-f56ae7fe]{padding:6px 10px}.modalbox[data-v-8db5af92] .el-dialog{min-width:550px}.selWidth[data-v-8db5af92]{width:350px!important}.seachTiele[data-v-8db5af92]{line-height:35px}.fa[data-v-8db5af92]{color:#0a6aa1;display:block}.sheng[data-v-8db5af92]{color:red;display:block}
|
@ -1 +0,0 @@
|
||||
.selWidth[data-v-0c96e7c6]{width:320px}
|
1
public/system/css/chunk-6de64421.ca31115d.css
Normal file
1
public/system/css/chunk-6de64421.ca31115d.css
Normal file
@ -0,0 +1 @@
|
||||
.box-container[data-v-1fabcbfd]{overflow:hidden}.box-container .list[data-v-1fabcbfd]{float:left;line-height:40px}.box-container .sp[data-v-1fabcbfd]{width:50%}.box-container .sp3[data-v-1fabcbfd]{width:33.3333%}.box-container .sp100[data-v-1fabcbfd]{width:100%}.box-container .list .name[data-v-1fabcbfd]{display:inline-block;width:150px;text-align:right;color:#606266}.box-container .list.image[data-v-1fabcbfd]{margin-bottom:40px}.box-container .list.image img[data-v-1fabcbfd]{position:relative;top:40px}[data-v-1fabcbfd] .el-form-item__content .el-rate{position:relative;top:8px}
|
@ -1 +0,0 @@
|
||||
[data-v-097ce6f6] .el-dialog{margin-top:0!important;width:820px}.mer_phone[data-v-097ce6f6]{width:400px}.dis[data-v-097ce6f6],.switch_btn[data-v-097ce6f6]{display:-webkit-box;display:-ms-flexbox;display:flex}.switch_btn[data-v-097ce6f6]{-ms-flex-wrap:wrap;flex-wrap:wrap}.switch_btn .mini_btn[data-v-097ce6f6]{width:390px!important}
|
File diff suppressed because one or more lines are too long
1
public/system/css/chunk-libs.d3e86ffa.css
Normal file
1
public/system/css/chunk-libs.d3e86ffa.css
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 233 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user