| xqd
@@ -24,6 +24,7 @@ use App\Models\AlbumXyxUserModel;
|
|
|
use App\Models\CustomerCatRecordModel;
|
|
|
use App\Models\CustomerDetailsModel;
|
|
|
use App\User;
|
|
|
+use EasyWeChat\Kernel\Messages\Text;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
| xqd
@@ -225,7 +226,7 @@ class AlbumController extends Controller
|
|
|
$user_agent->save();
|
|
|
$agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
|
|
|
try{
|
|
|
- $this->sendLogsMessage($datas['store_id'],$agent->open_id,4,$userAuth->username);
|
|
|
+ $this->sendLogsMessage($datas['store_id'],$agent->open_id,4,$userAuth->username,$agent->g_open_id);
|
|
|
}catch (\Exception $e){
|
|
|
|
|
|
}
|
| xqd
@@ -364,7 +365,7 @@ class AlbumController extends Controller
|
|
|
$user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
|
|
|
$agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
|
|
|
try{
|
|
|
- $this->sendLogsMessage($store_id,$agent->open_id,2,$userAuth->username);
|
|
|
+ $this->sendLogsMessage($store_id,$agent->open_id,2,$userAuth->username,$agent->g_open_id);
|
|
|
}catch (\Exception $e){
|
|
|
|
|
|
}
|
| xqd
@@ -498,7 +499,7 @@ class AlbumController extends Controller
|
|
|
$user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
|
|
|
$agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
|
|
|
try{
|
|
|
- $this->sendLogsMessage($store_id,$agent->open_id,3,$userAuth->username);
|
|
|
+ $this->sendLogsMessage($store_id,$agent->open_id,3,$userAuth->username,$agent->g_open_id);
|
|
|
}catch (\Exception $e){
|
|
|
|
|
|
}
|
| xqd
@@ -1316,7 +1317,7 @@ class AlbumController extends Controller
|
|
|
$user_agent = AlbumAgentModel::where('id',$userAuth->up_agent_id)->first();
|
|
|
$agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
|
|
|
try{
|
|
|
- $this->sendLogsMessage($data['store_id'],$agent->open_id,1,$userAuth->username);
|
|
|
+ $this->sendLogsMessage($data['store_id'],$agent->open_id,1,$userAuth->username,$agent->g_open_id);
|
|
|
}catch (\Exception $e){
|
|
|
|
|
|
}
|
| xqd
@@ -1661,7 +1662,7 @@ class AlbumController extends Controller
|
|
|
$add_record['agent_id'] = $userAuth->up_agent_id;
|
|
|
$add_record['open_id'] = $userAuth->open_id;
|
|
|
$add_record['action'] = $data['type'];
|
|
|
- $add_record['store_id'] = 1;
|
|
|
+ $add_record['store_id'] = $data['store_id'];
|
|
|
$add_record['detail'] = json_encode($select_info);
|
|
|
// dd($add_record);
|
|
|
$res = AlbumWatchRecord::create($add_record);
|
| xqd
@@ -1669,7 +1670,7 @@ class AlbumController extends Controller
|
|
|
$agent = AlbumUserModel::where('id',$user_agent->user_id)->first();
|
|
|
if($res){
|
|
|
try{
|
|
|
- $this->sendLogsMessage($data['store_id'],$agent->open_id,$data['type'],$userAuth->username);
|
|
|
+ $this->sendLogsMessage($data['store_id'],$agent->open_id,$data['type'],$userAuth->username,$agent->g_open_id);
|
|
|
}catch (\Exception $e){
|
|
|
|
|
|
}
|
| xqd
@@ -1686,7 +1687,7 @@ class AlbumController extends Controller
|
|
|
* @param $action 1 收藏 2查看类目 3查看商品 4登陆 5点击图片 6 点击导航 7一键拨号
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
|
*/
|
|
|
- private function sendLogsMessage($storeid,$open_id,$action,$name)
|
|
|
+ private function sendLogsMessage($storeid,$open_id,$action,$name,$g_open_id)
|
|
|
{
|
|
|
$user = AlbumUserModel::where('open_id',$open_id)->first();
|
|
|
$formId = AlbumFormId::where([['open_id',$open_id]])->first();
|
| xqd
@@ -1715,6 +1716,15 @@ class AlbumController extends Controller
|
|
|
$content = '有用户点击了您的号码';
|
|
|
break;
|
|
|
}
|
|
|
+ $weChatApp = AlbumManufacturerModel::where('store_id', $storeid)->first();
|
|
|
+ $config = [
|
|
|
+ 'app_id' => $weChatApp->G_app_id,
|
|
|
+ 'secret' => $weChatApp->G_app_secret,
|
|
|
+ 'response_type' => 'array',
|
|
|
+ ];
|
|
|
+ $app = Factory::officialAccount($config);
|
|
|
+ $text = new Text($content);
|
|
|
+ $app->customer_service->message($text)->to($g_open_id)->send();
|
|
|
$this->wechat_app = AlbumManufacturerModel::where('store_id',$storeid)->first();
|
|
|
$config = [
|
|
|
'app_id' => $this->wechat_app->app_id,
|
| xqd
@@ -2333,6 +2343,7 @@ class AlbumController extends Controller
|
|
|
* @apiPermission AUTH
|
|
|
* @apiVersion 0.1.0
|
|
|
* @apiParam {int} [store_id] 商户id
|
|
|
+ * @apiParam {int} [goods_id] 商品id
|
|
|
* @apiSuccessExample {json} Success-Response:
|
|
|
* HTTP/1.1 200 OK
|
|
|
* {
|
| xqd
@@ -2354,6 +2365,8 @@ class AlbumController extends Controller
|
|
|
*/
|
|
|
public function albumStatistical(Request $request)
|
|
|
{
|
|
|
+ $userAuth = Auth('api')->user();
|
|
|
+ if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
'store_id' => 'required',
|
|
|
'agent_id' => 'required'
|
| xqd
@@ -2365,14 +2378,14 @@ class AlbumController extends Controller
|
|
|
return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
|
|
|
}
|
|
|
$store_id = $request->input('store_id');
|
|
|
- $agent_id = $request->input('agent_id');
|
|
|
- if($agent_id!=0){
|
|
|
- $user_agent = AlbumAgentModel::where([['id',$agent_id],['status',1]])->first();
|
|
|
+ $goods_id = $request->input('goods_id');
|
|
|
+
|
|
|
+ if($userAuth->up_agent_id !=0){
|
|
|
+ $user_agent = AlbumAgentModel::where([['id',$userAuth->up_agent_id],['status',1]])->first();
|
|
|
$user_agent->share_times++;
|
|
|
$user_agent->save();
|
|
|
}
|
|
|
- $userAuth = Auth('api')->user();
|
|
|
- if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
|
|
|
+
|
|
|
$time = mktime(0,0,0,date('m'),date('d'),date('y'));
|
|
|
$check = AlbumStatisticalModel::where([['time',$time],['store_id',$store_id]])->first();
|
|
|
if($check){
|
| xqd
@@ -2385,6 +2398,102 @@ class AlbumController extends Controller
|
|
|
$add['favorite_times'] = 0;
|
|
|
AlbumStatisticalModel::create($add);
|
|
|
}
|
|
|
+ if($userAuth->up_agent_id!=0 && !empty($goods_id)){
|
|
|
+ $add_record['agent_id'] = $userAuth->up_agent_id;
|
|
|
+ $add_record['open_id'] = $userAuth->open_id;
|
|
|
+ $add_record['action'] = 8;
|
|
|
+ $add_record['store_id'] = $store_id;
|
|
|
+ $add_record['detail'] = $goods_id;
|
|
|
+ $res = AlbumWatchRecord::create($add_record);
|
|
|
+ }
|
|
|
return $this->api([],0,'success');
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @api {post} /api/album/get_statistical 获取分享记录(get-statistical)
|
|
|
+ * @apiDescription 获取分享记录(get-statistical)
|
|
|
+ * @apiGroup Album
|
|
|
+ * @apiPermission AUTH
|
|
|
+ * @apiVersion 0.1.0
|
|
|
+ * @apiParam {int} [store_id] 商户id
|
|
|
+ * @apiParam {int} [type] 1 尺寸统计 2拨打电话 3 分享
|
|
|
+ * @apiSuccessExample {json} Success-Response:
|
|
|
+ * HTTP/1.1 200 OK
|
|
|
+ * {
|
|
|
+ * "status": true,
|
|
|
+ * "status_code": 0,
|
|
|
+ * "message": "success",
|
|
|
+ * "data":[
|
|
|
+ * {
|
|
|
+ * 'content':xxxxx,
|
|
|
+ * 'time':xxx-xx-xx,
|
|
|
+ * },
|
|
|
+ * ]
|
|
|
+ * }
|
|
|
+ * @apiErrorExample {json} Error-Response:
|
|
|
+ * HTTP/1.1 400 Bad Request
|
|
|
+ * {
|
|
|
+ * "state": false,
|
|
|
+ * "code": 1000,
|
|
|
+ * "message": "传入参数不正确",
|
|
|
+ * "data": null or []
|
|
|
+ * }
|
|
|
+ * 可能出现的错误代码:
|
|
|
+ * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
|
|
|
+ */
|
|
|
+ public function albumGetStatistical(Request $request)
|
|
|
+ {
|
|
|
+ $userAuth = Auth('api')->user();
|
|
|
+ if(!$userAuth) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '未登录!');
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'store_id' => 'required',
|
|
|
+ 'type' => 'required',
|
|
|
+ ],[
|
|
|
+ 'store_id.required'=>'缺少商户参数',
|
|
|
+ 'type.required'=>'缺少类型参数',
|
|
|
+ ]);
|
|
|
+ if ($validator->fails()) {
|
|
|
+ return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
|
|
|
+ }
|
|
|
+ $data = $request->input();
|
|
|
+ if($userAuth->is_dealer!=1) return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '该用户不是经销商!', $validator->messages());
|
|
|
+ $user_agent = AlbumAgentModel::where('user_id',$userAuth->id)->first();
|
|
|
+ if ($data['type'] == 1) { //尺寸统计
|
|
|
+ $record = AlbumWatchRecord::where([['agent_id',$user_agent->id],['detail','lick','%\u5c3a\u5bf8\u56fe%'],['action',5],['store_id',$data['store_id']]])->get();
|
|
|
+ foreach ($record as $key=>$val){
|
|
|
+ $user = AlbumUserModel::where([['open_id',$val->open_id],['store_id',$data['store_id']]])->first();
|
|
|
+ $detail = json_decode($val->detail,true);
|
|
|
+ $goods = AlbumProductModel::where([['store_id',$data['store_id'].['id',$detail['goods_id']]]])->first();
|
|
|
+ if (!$goods) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $res[] = [
|
|
|
+ 'content' => $user->username . '点击' . $goods->name . $detail['detail'],
|
|
|
+ 'time' => date('Y-m-d H:i',strtotime($val->created_at))
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ } elseif ($data['type'] == 2) { //拨打电话
|
|
|
+ $record = AlbumWatchRecord::where([['agent_id',$user_agent->id],['action',7],['store_id',$data['store_id']]])->get();
|
|
|
+ foreach ($record as $key=>$val){
|
|
|
+ $user = AlbumUserModel::where([['open_id',$val->open_id],['store_id',$data['store_id']]])->first();
|
|
|
+ $res[] = [
|
|
|
+ 'content' => $user->username . '拨打了经销商电话',
|
|
|
+ 'time' => date('Y-m-d H:i',strtotime($val->created_at))
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $record = AlbumWatchRecord::where([['agent_id',$user_agent->id],['action',8],['store_id',$data['store_id']]])->get();
|
|
|
+ foreach ($record as $key=>$val){
|
|
|
+ $goods = AlbumProductModel::where([['store_id',$data['store_id'].['id',$val->detail]]])->first();
|
|
|
+ $style = AlbumProductStyleModel::where([['store_id',$data['store_id'].['id',$goods->style]]])->first();
|
|
|
+ $cat = AlbumCatModel::where([['store_id',$data['store_id'].['id',$goods->cat_id]]])->first();
|
|
|
+ $user = AlbumUserModel::where([['open_id',$val->open_id],['store_id',$data['store_id']]])->first();
|
|
|
+ $res[] = [
|
|
|
+ 'content' => "$user->username 分享了 $style->name $cat->name $goods->name ",
|
|
|
+ 'time' => date('Y-m-d H:i',strtotime($val->created_at))
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|