|
@@ -51,9 +51,15 @@ class SecurityCodeRecordServices extends BaseServices
|
|
|
$item['point'] = $item['category']['point'] ?? '';
|
|
|
$item['category_name'] = $item['category']['name'] ?? '';
|
|
|
$item['category_status'] = $item['category']['status'] ?? '';
|
|
|
+ $item['scan_name'] = '-';
|
|
|
+ $item['city_name'] = '-';
|
|
|
+ $item['store_name'] = '-';
|
|
|
+ $item['scan_phone'] = '-';
|
|
|
if($item['scan_uid']){
|
|
|
$userInfo = $userServices->getUserInfo((int)$item['scan_uid']);
|
|
|
- $item['scan_name'] = $userInfo['nickname'] ?? '';
|
|
|
+ $item['scan_name'] = $userInfo['nickname']."-".$userInfo['phone'];
|
|
|
+ $item['city_name'] = $userInfo['city_name'] ?? '';
|
|
|
+ $item['store_name'] = $userInfo['store_name'] ?? '';
|
|
|
$item['scan_phone'] = $userInfo['phone'] ?? '';
|
|
|
}
|
|
|
unset($item['category']);
|
|
@@ -62,6 +68,40 @@ class SecurityCodeRecordServices extends BaseServices
|
|
|
return compact('list', 'count');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param array $where
|
|
|
+ * @return array
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function getSearchAllList(array $where = [])
|
|
|
+ {
|
|
|
+ [$page, $limit] = $this->getPageValue();
|
|
|
+ $list = $this->dao->getSearchList($where);
|
|
|
+ $userServices = app()->make(UserServices::class);
|
|
|
+ foreach ($list as &$item) {
|
|
|
+ $item['price'] = $item['category']['price'] ?? '';
|
|
|
+ $item['point'] = $item['category']['point'] ?? '';
|
|
|
+ $item['category_name'] = $item['category']['name'] ?? '';
|
|
|
+ $item['category_status'] = $item['category']['status'] ?? '';
|
|
|
+ $item['scan_name'] = '-';
|
|
|
+ $item['city_name'] = '-';
|
|
|
+ $item['store_name'] = '-';
|
|
|
+ $item['scan_phone'] = '-';
|
|
|
+ if($item['scan_uid']){
|
|
|
+ $userInfo = $userServices->getUserInfo((int)$item['scan_uid']);
|
|
|
+ $item['scan_name'] = $userInfo['nickname']."-".$userInfo['phone'];
|
|
|
+ $item['city_name'] = $userInfo['city_name'] ?? '';
|
|
|
+ $item['store_name'] = $userInfo['store_name'] ?? '';
|
|
|
+ $item['scan_phone'] = $userInfo['phone'] ?? '';
|
|
|
+ }
|
|
|
+ unset($item['category']);
|
|
|
+ }
|
|
|
+ $count = $this->dao->count($where);
|
|
|
+ return compact('list', 'count');
|
|
|
+ }
|
|
|
+
|
|
|
/**获取会员卡api接口
|
|
|
* @return mixed
|
|
|
*/
|
|
@@ -76,6 +116,15 @@ class SecurityCodeRecordServices extends BaseServices
|
|
|
*/
|
|
|
public function receiveSecurityCodePoint(int $uid, array $data)
|
|
|
{
|
|
|
+ /** @var UserServices $userServices */
|
|
|
+ $userServices = app()->make(UserServices::class);
|
|
|
+
|
|
|
+ //检测用户是否存在
|
|
|
+ $user = $userServices->getUserInfo($uid);
|
|
|
+ if (!$user) {
|
|
|
+ throw new ApiException(100026);
|
|
|
+ }
|
|
|
+
|
|
|
$codeRecord = $this->dao->getOne($data);
|
|
|
if(!$codeRecord){
|
|
|
throw new ApiException(600001);
|
|
@@ -83,41 +132,35 @@ class SecurityCodeRecordServices extends BaseServices
|
|
|
if($codeRecord['status']==2){
|
|
|
throw new ApiException(600003);
|
|
|
}
|
|
|
- /** @var UserServices $userServices */
|
|
|
- $userServices = app()->make(UserServices::class);
|
|
|
|
|
|
- //检测用户是否存在
|
|
|
- $user = $userServices->getUserInfo($uid);
|
|
|
- if (!$user) {
|
|
|
- throw new ApiException(410032);
|
|
|
- }
|
|
|
$categoryServices = app()->make(SecurityCategoryServices::class);
|
|
|
$cateInfo = $categoryServices->getOne(['id' => $codeRecord['category_id']]);
|
|
|
|
|
|
$codeRecord['status'] = 2;
|
|
|
$codeRecord['scan_uid'] = $uid;
|
|
|
$codeRecord['scan_time'] = time();
|
|
|
- $point = $codeRecord['id'];
|
|
|
+ $point = $cateInfo['point'];
|
|
|
|
|
|
$data = [];
|
|
|
$data['uid'] = $uid;
|
|
|
- $data['link_id'] = $point;
|
|
|
- $data['title'] = "扫码领积分";
|
|
|
+ $data['link_id'] = $codeRecord['id'];
|
|
|
+ $data['title'] = "扫防伪码领积分";
|
|
|
$data['number'] = $cateInfo['point'];
|
|
|
$data['add_time'] = time();
|
|
|
/** @var UserBillServices $userBill */
|
|
|
$userBill = app()->make(UserBillServices::class);
|
|
|
- $data['mark'] = "扫码领取了".$point."积分";
|
|
|
+ $data['mark'] = "扫防伪码领取了".$point."积分";
|
|
|
|
|
|
//增加数据
|
|
|
$this->transaction(function () use ($uid, $userBill, $codeRecord, $data, $user, $point) {
|
|
|
//保存记录
|
|
|
$this->dao->update($codeRecord['id'], ['status' => 2, 'scan_uid' => $uid, 'scan_time' => time()]);
|
|
|
- $userBill->incomeIntegral($uid, 'security', $data);
|
|
|
+ $data['balance'] = (int)$user['integral'] + (int)$point;
|
|
|
+ $userBill->incomeIntegral($user['uid'], 'system_add', $data);
|
|
|
//保存积分
|
|
|
$user->integral = (int)$user->integral + (int)$point;
|
|
|
if (!$user->save()) {
|
|
|
- throw new ApiException(410287);
|
|
|
+ throw new ApiException(400692);
|
|
|
}
|
|
|
});
|
|
|
//检测会员等级
|
|
@@ -178,4 +221,19 @@ class SecurityCodeRecordServices extends BaseServices
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ public function delCode(int $id)
|
|
|
+ {
|
|
|
+ if ($this->getById($id)) {
|
|
|
+ if (!$this->dao->delete($id)) {
|
|
|
+ throw new AdminException(100008);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getById($id)
|
|
|
+ {
|
|
|
+ return $this->dao->get($id);
|
|
|
+ }
|
|
|
+
|
|
|
}
|