调整用户收货地址保存

This commit is contained in:
luofei 2024-02-20 11:42:18 +08:00
parent d6617700cc
commit 87788ab44e
5 changed files with 73 additions and 14 deletions

View File

@ -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
@ -43,4 +44,10 @@ class UserAddressDao extends BaseDao
{
return (($this->getModel()::getDB())->where('uid',$uid));
}
public function villageExists($field, $value): bool
{
return ((GeoVillage::getDB())->where($field,$value)->count()) > 0;
}
}

View File

@ -485,6 +485,7 @@ class SpuRepository extends BaseRepository
if ($coupon) {
switch ($coupon['type']) {
case 0:
case 2:
$where['mer_id'] = $coupon['mer_id'];
break;
case 1:
@ -499,6 +500,7 @@ class SpuRepository extends BaseRepository
$where['cate_pid'] = $ids;
break;
case 10:
case 13:
break;
case 12:
$ids = app()->make(StoreCouponProductRepository::class)->search([

View File

@ -119,4 +119,10 @@ class UserAddressRepository extends BaseRepository
{
return $this->dao->getWhere(['address_id' => $id,'uid' => $uid])->append(['area']);
}
public function villageExists($field, $value)
{
return $this->dao->villageExists($field, $value);
}
}

View File

@ -13,6 +13,11 @@
namespace app\controller\api\user;
use app\common\model\store\GeoArea;
use app\common\model\store\GeoCity;
use app\common\model\store\GeoProvince;
use app\common\model\store\GeoStreet;
use app\common\model\store\GeoVillage;
use app\common\repositories\store\CityAreaRepository;
use think\App;
use crmeb\basic\BaseController;
@ -125,30 +130,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;

View File

@ -16,7 +16,7 @@ class OrderDeliveryListen implements ListenerInterface
$order = $event['order'];
foreach ($order->orderProduct as $orderProduct) {
$merchantCate = $orderProduct->product->merCateId;
if (empty($merchantCate) || $merchantCate[0]['mer_cate_id']!= env('PLATFORM_CARD_TYPE_ID')) {
if (empty($merchantCate) || $merchantCate[0]['mer_cate_id'] != env('PLATFORM_CARD_TYPE_ID')) {
continue;
}
/** @var StoreCouponRepository $repo */
@ -27,7 +27,7 @@ class OrderDeliveryListen implements ListenerInterface
return;
}
$coupon->coupon_price = bcmul($orderProduct->product_num, $orderProduct->product->price);
$repo->sendCoupon($coupon, $order['uid'],StoreCouponUserRepository::SEND_TYPE_BUY);
$repo->sendCoupon($coupon, $order['uid'], StoreCouponUserRepository::SEND_TYPE_BUY);
}
}