Browse Source

Merge branch 'feature/v3.0.14' into master

master
weigang 5 years ago
parent
commit
59c97b9978
  1. 2
      app/Constants/v3/SmsTemplateCode.php
  2. 26
      app/Controller/v3/NotifyController.php
  3. 15
      app/Model/v3/GoodsActivity.php
  4. 6
      app/Service/v3/Implementations/ActivityService.php
  5. 2
      app/Service/v3/Implementations/FinancialRecordService.php
  6. 21
      app/Service/v3/Implementations/SearchService.php
  7. 12
      app/Service/v3/Implementations/SeparateAccountsService.php
  8. 21
      app/Service/v3/Implementations/SmsAliSendService.php
  9. 12
      app/Service/v3/Implementations/UserInfoService.php
  10. 2
      app/Service/v3/Interfaces/SmsSendServiceInterface.php
  11. 2
      app/Service/v3/Interfaces/UserInfoServiceInterface.php

2
app/Constants/v3/SmsTemplateCode.php

@ -18,7 +18,7 @@ class SmsTemplateCode extends AbstractConstants
/** /**
* @Message("社区服务点奖励流水") * @Message("社区服务点奖励流水")
*/ */
const ALI_COMMUNITY_FINANCIAL = 'SMS_200690862';
const ALI_COMMUNITY_FINANCIAL = 'SMS_205122825';
/** /**
* @Message("微信打款失败") * @Message("微信打款失败")

26
app/Controller/v3/NotifyController.php

@ -12,6 +12,7 @@ use App\Model\v3\GoodsActivity;
use App\Model\v3\Order; use App\Model\v3\Order;
use App\Model\v3\OrderGoods; use App\Model\v3\OrderGoods;
use App\Model\v3\OrderMain; use App\Model\v3\OrderMain;
use App\Model\v3\User;
use App\Service\v3\Interfaces\BadgeServiceInterface; use App\Service\v3\Interfaces\BadgeServiceInterface;
use App\Service\v3\Interfaces\CouponRebateServiceInterface; use App\Service\v3\Interfaces\CouponRebateServiceInterface;
use App\Service\v3\Interfaces\CouponServiceInterface; use App\Service\v3\Interfaces\CouponServiceInterface;
@ -25,6 +26,7 @@ use App\Service\v3\Interfaces\OrderOfflineServiceInterface;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
use App\Service\v3\Interfaces\OrderStatisticsServiceInterface; use App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
use App\Service\v3\Interfaces\SeparateAccountsServiceInterface; use App\Service\v3\Interfaces\SeparateAccountsServiceInterface;
use App\Service\v3\Interfaces\UserInfoServiceInterface;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
use Hyperf\Guzzle\CoroutineHandler; use Hyperf\Guzzle\CoroutineHandler;
@ -114,6 +116,12 @@ class NotifyController extends BaseController
*/ */
protected $orderStatisticsService; protected $orderStatisticsService;
/**
* @Inject
* @var UserInfoServiceInterface
*/
protected $userInfoService;
public function wxminiOnline() public function wxminiOnline()
{ {
@ -189,6 +197,15 @@ class NotifyController extends BaseController
// 公众号模板消息 // 公众号模板消息
$res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMain->global_order_id); $res = $this->miniprogramService->sendTemMsgForOnlineOrder($orderMain->global_order_id);
co(function () use ($orderMain) {
$openid = User::query()->where(['id' => $orderMain->user_id])->value('openid');
$unionid = $this->userInfoService->getPaidUnionId($openid, ['mch_id' => config('wxpay.mch_id'), 'out_trade_no' => $orderMain->global_order_id]);
if ($unionid) {
User::query()->where(['id' => $orderMain->user_id, 'openid' => $openid])->update(['unionid' => $unionid]);
}
});
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
@ -276,6 +293,15 @@ class NotifyController extends BaseController
// 公众号模板消息 // 公众号模板消息
$res = $this->miniprogramService->sendTemMsgForOfflineOrder($orderMain->global_order_id); $res = $this->miniprogramService->sendTemMsgForOfflineOrder($orderMain->global_order_id);
co(function () use ($orderMain) {
$openid = User::query()->where(['id' => $orderMain->user_id])->value('openid');
$unionid = $this->userInfoService->getPaidUnionId($openid, ['mch_id' => config('wxpay.mch_id'), 'out_trade_no' => $orderMain->global_order_id]);
if ($unionid) {
User::query()->where(['id' => $orderMain->user_id, 'openid' => $openid])->update(['unionid' => $unionid]);
}
});
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {

15
app/Model/v3/GoodsActivity.php

@ -76,12 +76,23 @@ class GoodsActivity extends Model
public function getIsEffectiveAttribute() public function getIsEffectiveAttribute()
{ {
return 2;
if ($this->attributes['expire_time'] < time() || ($this->attributes['inventory'] <= 0 && $this->attributes['is_infinite'] != 1)) {
return 1;
}
return 0;
} }
public function getNoneffectiveNoteAttribute() public function getNoneffectiveNoteAttribute()
{ {
return '已抢光';
$msg = '';
if ($this->attributes['expire_time'] < time()) {
$msg = '已结束';
} elseif ($this->attributes['inventory'] <= 0 && $this->attributes['is_infinite'] != 1) {
$msg = '已抢光';
}
return $msg;
} }
public function getTotalSecondsAttribute() public function getTotalSecondsAttribute()

6
app/Service/v3/Implementations/ActivityService.php

@ -41,9 +41,9 @@ class ActivityService implements ActivityServiceInterface
->orWhereJsonLength(''.$goodsTable.'.market_ids', '=', 0); ->orWhereJsonLength(''.$goodsTable.'.market_ids', '=', 0);
}) })
->where([''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES]) ->where([''.$goodsTable.'.on_sale' => GoodsConstants::ON_SALE_YES])
->where(function ($query) use ($goodsTable) {
$query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1);
})
// ->where(function ($query) use ($goodsTable) {
// $query->where(''.$goodsTable.'.inventory', '>', 0)->orWhere(''.$goodsTable.'.is_infinite', '=', 1);
// })
->whereRaw(''.$goodsTable.'.deleted_at IS NULL') ->whereRaw(''.$goodsTable.'.deleted_at IS NULL')
->where([''.$storeTable.'.market_id' => $marketId]) ->where([''.$storeTable.'.market_id' => $marketId])
->where([''.$storeTable.'.is_open' => \App\Constants\v3\Store::IS_OPEN_YES]) ->where([''.$storeTable.'.is_open' => \App\Constants\v3\Store::IS_OPEN_YES])

2
app/Service/v3/Implementations/FinancialRecordService.php

@ -34,7 +34,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface
{ {
// 如果金额不存在或者金额为0时,不记账 // 如果金额不存在或者金额为0时,不记账
if (!isset($record['money']) || !boolval($record['money'])) {
if (!isset($record['money']) || $record['money'] == 0) {
return true; return true;
} }

21
app/Service/v3/Implementations/SearchService.php

@ -20,6 +20,8 @@ class SearchService implements SearchServiceInterface
public function doForGoods($params) public function doForGoods($params)
{ {
$params['pagesize'] = $params['pagesize'] ?: 10;
$storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable(); $storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable();
$goodsTable = ApplicationContext::getContainer()->get(Goods::class)->getTable(); $goodsTable = ApplicationContext::getContainer()->get(Goods::class)->getTable();
@ -92,14 +94,29 @@ class SearchService implements SearchServiceInterface
} }
$builder->select(''.$goodsTable.'.*')->addSelect([''.$goodsTable.'.sales as total_sales']); $builder->select(''.$goodsTable.'.*')->addSelect([''.$goodsTable.'.sales as total_sales']);
// Feature/搜索商品也展示出三级分类
$allGoodsCategoryIds = $builder->groupBy(''.$goodsTable.'.goods_category_id')->pluck('goods_category_id');
$goodsCategories = GoodsCategory::query()
->whereIn('id', $allGoodsCategoryIds)
->get()
->toArray();
$goodsCategoryIds = implode(',', array_values(array_column($goodsCategories, 'id')));
$paginate = $builder->groupBy(''.$goodsTable.'.id')->inRandomOrder()->paginate($params['pagesize']); $paginate = $builder->groupBy(''.$goodsTable.'.id')->inRandomOrder()->paginate($params['pagesize']);
$goods = $paginate->toArray(); $goods = $paginate->toArray();
return ['has_more_pages' => $paginate->hasMorePages(), 'goods' => $goods['data']];
return [
'has_more_pages' => $paginate->hasMorePages(),
'goods' => $goods['data'],
'category' => ['goods_category' => $goodsCategories, 'goods_category_ids' => $goodsCategoryIds]
];
} }
public function doForStores($params) public function doForStores($params)
{ {
$params['pagesize'] = $params['pagesize'] ?: 10;
$storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable(); $storeTable = ApplicationContext::getContainer()->get(Store::class)->getTable();
$goodsTable = ApplicationContext::getContainer()->get(Goods::class)->getTable(); $goodsTable = ApplicationContext::getContainer()->get(Goods::class)->getTable();
@ -142,7 +159,9 @@ class SearchService implements SearchServiceInterface
$builder->orderByDefault($sort); $builder->orderByDefault($sort);
break; break;
} }
} }
$paginate = $builder->groupBy(''.$storeTable.'.id')->inRandomOrder()->paginate($params['pagesize']); $paginate = $builder->groupBy(''.$storeTable.'.id')->inRandomOrder()->paginate($params['pagesize']);
$stores = $paginate->map(function ($item, $key) { $stores = $paginate->map(function ($item, $key) {
$item->goods; $item->goods;

12
app/Service/v3/Implementations/SeparateAccountsService.php

@ -146,8 +146,8 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface
$award['new_user_reward'] $award['new_user_reward']
); );
// 发送短信 // 发送短信
co(function () use ($communityBind, $award) {
$this->smsAliSendService->doCommunityFinancial($communityBind->source_id, $award['new_user_reward']);
co(function () use ($communityBind, $award, $orderMain) {
$this->smsAliSendService->doCommunityFinancial($communityBind->source_id, $award['new_user_reward'], $orderMain);
}); });
$this->financialRecordService->communityAwardByPlatNewUserFirstOLOrder( $this->financialRecordService->communityAwardByPlatNewUserFirstOLOrder(
$communityBind->source_id, $communityBind->source_id,
@ -155,16 +155,16 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface
$award['first_reward'] $award['first_reward']
); );
// 发送短信 // 发送短信
co(function () use ($communityBind, $award) {
$this->smsAliSendService->doCommunityFinancial($communityBind->source_id, $award['first_reward']);
co(function () use ($communityBind, $award, $orderMain) {
$this->smsAliSendService->doCommunityFinancial($communityBind->source_id, $award['first_reward'], $orderMain);
}); });
} }
// 账单分成 // 账单分成
$money = bcmul($orderMain->money, bcdiv($award['flow_reward'], 100, 6), 2); $money = bcmul($orderMain->money, bcdiv($award['flow_reward'], 100, 6), 2);
$this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $orderMain->global_order_id, $money); $this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $orderMain->global_order_id, $money);
// 发送短信 // 发送短信
co(function () use ($communityBind, $money) {
$this->smsAliSendService->doCommunityFinancial($communityBind->source_id, $money);
co(function () use ($communityBind, $money, $orderMain) {
$this->smsAliSendService->doCommunityFinancial($communityBind->source_id, $money, $orderMain);
}); });
} }

21
app/Service/v3/Implementations/SmsAliSendService.php

@ -88,12 +88,25 @@ class SmsAliSendService implements SmsSendServiceInterface
// TODO: Implement removeVerifyCode() method. // TODO: Implement removeVerifyCode() method.
} }
public function doCommunityFinancial($userId, $money)
public function doCommunityFinancial($csUserAdminId, $money, $orderMain)
{ {
$csInfo = CsInfo::query()->where(['admin_user_id' => $userId])->first();
$market = Market::query()->where(['id' => $csInfo->market_id])->first();
$params = ['user_name' => $csInfo->name, 'market_name' => $market->name, 'money' => $money];
if ($money == 0) {
return true;
}
$csInfo = CsInfo::query()->where(['admin_user_id' => $csUserAdminId])->first();
$market = Market::query()->where(['id' => $orderMain->market_id])->first();
// $params = ['user_name' => $csInfo->name, 'market_name' => $market->name, 'money' => $money];
$orderTel = substr_replace($orderMain->tel, '****', 3, 4);
$params = [
'store_name' => ' ['.$csInfo->name.'] ',
'markert_name' => ' ['.$market->name.'] ',
'user_name' => $orderMain->name.'(懒ID:'.$orderMain->user_id.')',
'pay_money' => $orderMain->money.'元',
'money' => $money.'元'
];
return $this->do($csInfo->phone, SmsTemplateCode::ALI_COMMUNITY_FINANCIAL, json_encode($params)); return $this->do($csInfo->phone, SmsTemplateCode::ALI_COMMUNITY_FINANCIAL, json_encode($params));
} }

12
app/Service/v3/Implementations/UserInfoService.php

@ -103,4 +103,16 @@ class UserInfoService implements UserInfoServiceInterface
return $employees; return $employees;
} }
public function getPaidUnionId($openid, $options = [])
{
$config = config('applet');
$app = Factory::miniProgram($config);
$app['guzzle_handler'] = CoroutineHandler::class;
$res = $app->base->getPaidUnionid($openid, $options);
if (isset($res['unionid']) && $res['unionid']) {
return $res['unionid'];
} else {
return false;
}
}
} }

2
app/Service/v3/Interfaces/SmsSendServiceInterface.php

@ -10,6 +10,6 @@ interface SmsSendServiceInterface
public function doVerifyCode($tel, $code); public function doVerifyCode($tel, $code);
public function checkVerifyCode($tel, $code); public function checkVerifyCode($tel, $code);
public function undoVerifyCode($tel, $code); public function undoVerifyCode($tel, $code);
public function doCommunityFinancial($userId, $money);
public function doCommunityFinancial($csUserAdminId, $money, $orderMain);
public function doWithdrawFail($storeName, $money, $errorCode, $errorCodeDes); public function doWithdrawFail($storeName, $money, $errorCode, $errorCodeDes);
} }

2
app/Service/v3/Interfaces/UserInfoServiceInterface.php

@ -10,5 +10,5 @@ interface UserInfoServiceInterface
public function detail($userId); public function detail($userId);
public function getStoreByUID($userId); public function getStoreByUID($userId);
public function getEmployeesByUID($userId); public function getEmployeesByUID($userId);
public function getPaidUnionId($openid, $options = []);
} }
Loading…
Cancel
Save