6 changed files with 360 additions and 18 deletions
-
167app/Controller/NotifyController.php
-
9app/Model/StoreAccount.php
-
66app/Service/MiniprogramService.php
-
32app/Service/MiniprogramServiceInterface.php
-
76app/Service/UserService.php
-
28app/Service/UserServiceInterface.php
@ -0,0 +1,9 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Model; |
||||
|
|
||||
|
class StoreAccount extends Model |
||||
|
{ |
||||
|
protected $table = 'ims_cjdc_store_account'; |
||||
|
public $timestamps = false; |
||||
|
} |
||||
@ -0,0 +1,76 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Service; |
||||
|
|
||||
|
use App\Model\Order; |
||||
|
use App\Model\OrderMain; |
||||
|
use App\Model\Users; |
||||
|
|
||||
|
class UserService implements UserServiceInterface |
||||
|
{ |
||||
|
|
||||
|
/** |
||||
|
* 是否平台新用户 |
||||
|
* 在很多奖励的地方会需要用到这个查询 |
||||
|
* 判定条件: |
||||
|
* 没有在平台下过单(包括线上和线下) |
||||
|
* @param $user_id |
||||
|
* @return mixed|void |
||||
|
*/ |
||||
|
public function isStageNewUser($user_id): bool |
||||
|
{ |
||||
|
$exist = OrderMain::query() |
||||
|
->where(['user_id' => $user_id]) |
||||
|
->where(function ($query){ |
||||
|
$query->where('state', 'in', [4,5,10]) |
||||
|
->orWhere('dm_state', 'in', [2,3]); |
||||
|
}) |
||||
|
->exists(); |
||||
|
|
||||
|
return !$exist; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 根据用户的openid更新unionid信息 |
||||
|
* 如果没有找到用户,则不做任何处理 |
||||
|
* @param $openid |
||||
|
* @param $unionid |
||||
|
* @return array |
||||
|
*/ |
||||
|
public function saveUserUnionid($openid,$unionid) |
||||
|
{ |
||||
|
$result = [ |
||||
|
'status' => false, |
||||
|
'msg' => '用户不存在或者已存在相同unionid' |
||||
|
]; |
||||
|
|
||||
|
// 查询用户是否存在
|
||||
|
$userinfo = Users::select('id','unionid')->where('openid',$openid)->first(); |
||||
|
if($userinfo && $userinfo->unionid != $unionid){ |
||||
|
$userinfo->unionid = $unionid; |
||||
|
if($res = $userinfo->save()){ |
||||
|
$result['status'] = true; |
||||
|
$result['msg'] = '更改用户unionid信息成功'; |
||||
|
$result['res'] = $res; |
||||
|
}else{ |
||||
|
$result['msg'] = '更改用户unionid信息失败'; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return $result; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @inheritDoc |
||||
|
*/ |
||||
|
public function isStoreFirstOrderToday($user_id, $store_id, $current_order_id, $limit_amount = 3) |
||||
|
{ |
||||
|
return !Order::query() |
||||
|
->where(['user_id' => $user_id, 'store_id' => $store_id, 'dm_state' => 2]) |
||||
|
->where('time_add', '>=', date('Y-m-d 00:00:00')) |
||||
|
->where('time_add', '<=', date('Y-m-d 23:59:59')) |
||||
|
->where('money', '>=', $limit_amount) |
||||
|
->where('id', '!=', $current_order_id) |
||||
|
->exists(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Service; |
||||
|
|
||||
|
|
||||
|
interface UserServiceInterface |
||||
|
{ |
||||
|
/** |
||||
|
* 是否平台新用户 |
||||
|
* @param $user_id |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function isStageNewUser($user_id): bool; |
||||
|
|
||||
|
public function saveUserUnionid($openid,$unionid); |
||||
|
|
||||
|
/** |
||||
|
* 是否店铺当日首单 |
||||
|
* @param $user_id |
||||
|
* @param $store_id |
||||
|
* @param $current_order_id |
||||
|
* @param int $limit_amount |
||||
|
* @return mixed |
||||
|
*/ |
||||
|
public function isStoreFirstOrderToday($user_id, $store_id, $current_order_id, $limit_amount = 3); |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue