pushVerify($param); if ($verifyResult['status'] != 1) { return $verifyResult; } try { $VipInfoClass = new VipInfo(); $vipResult = $VipInfoClass->basisPhoneGetVip([ 'merchant_id' => $param['merchant_id'], 'mobile_phone' => $param['vipPhone'] ]); //会员信息获取 if ($vipResult['status'] != 1) { return $vipResult; } $XcxUserClass = new XcxUser(); $xcxResult = $XcxUserClass->basisVipIdGetUser([ 'merchant_id' => $param['merchant_id'], 'vip_id' => $vipResult['data']['id'] ]); //获取小程序用户信息 if ($xcxResult['status'] != 1) { return $xcxResult; } $xcxUser = $xcxResult['data']; $StoreClass = new Store(); $storeList = $StoreClass->storeListInfo([ 'merchant_id' => $param['merchant_id'], 'fields'=>"id,storetag,address,phone" ]); if (empty($storeList)) { return callBack(statusCode()['error'], "缺少门店信息"); } $tempSend = array( 'merchant_id' => $param['merchant_id'], 'openid' => $xcxUser['openid'], 'type' => $param['type'], 'sendData' => array( 'store_name' => $storeList[0]['storetag'], 'order_no' => '123456789', 'price' => 1, 'add_time' => date('Y-m-d H:i:s', time()), 'goods_name' => '测试商品', 'pick_time' => date('Y-m-d H:i:s', time()), 'user_phone' => $param['vipPhone'], 'username' => '测试姓名', 'user_remark' => '测试备注', 'store_address' => $storeList[0]['address'], 'store_phone' => $storeList[0]['phone'], 'order_type' => '普通订单', ), ); switch ($param['type']) { case 1: //自提 $tempSend['sendData']['pick_code'] = '123456'; break; case 2: //发货 $tempSend['sendData']['delivery_type'] = '快递'; $tempSend['sendData']['delivery_time'] = date('Y-m-d H:i:s', time()); $tempSend['sendData']['user_address'] = '测试地址'; break; case 3: //分期到账 $tempSend = array( 'store_id' => $storeList[0]['id'], 'type' => 3, 'sendData' => array( 'aging_money' => 1, 'has_arrive' => 1, 'aging_date' => date('Y-m-d H:i:s', time()), 'un_arrive' => 1, ), ); break; } $result = A('Api/XcxMark')->sendMark($tempSend); $result = json_decode($result, true); if ($result['errcode'] === 0) { return callBack(statusCode()['success'], "发送成功"); } else { return callBack(statusCode()['error'], "发送失败,请检查小程序配置" . $result['errmsg']); } } catch (\Exception $e) { return callBack(statusCode()['error'], "发送失败,请检查小程序配置"); } } /** * 商户公众号测试模板推送 * @param $param * [ * merchant_id * type 模板类型 * vipPhone 会员手机号 * ] * @return mixed */ public function push($param) { // var_dump($param); $verifyResult = $this->pushVerify($param); //参数验证 if ($verifyResult['status'] != 1) { return $verifyResult; } try { if($param['type'] != 9){ $VipInfoClass = new VipInfo(); $vipResult = $VipInfoClass->basisPhoneGetVip([ 'merchant_id' => $param['merchant_id'], 'mobile_phone' => $param['vipPhone'] ]); //会员信息获取 if ($vipResult['status'] != 1) { return $vipResult; } $vipInfo = $vipResult['data']; if (empty($vipInfo['openid'])) { return callBack(statusCode()['error'], "未获取到该会员在公众号的唯一标识openid"); } } $MarkClass = new MarkController(); switch ($param['type']) { case 2: case 3: case 5: case 7: $StoreClass = new Store(); $storeList = $StoreClass->getStoreList([ 'merchant_id' => $param['merchant_id'] ]); if (empty($storeList)) { return callBack(statusCode()['error'], "缺少门店信息"); } $store_id = $storeList[0]['id']; break; } switch ($param['type']) { case 1: //会员卡激活 $result = $MarkClass->membershipsuccess($vipInfo['id']); break; case 2: //会员卡充值 $result = $MarkClass->rechargesuccess($store_id, $vipInfo['id'], 1, 1, "会员充值"); break; case 3: //会员消费 $result = $MarkClass->paysuccess($store_id, $vipInfo['id'], 1, "会员支付", ['ordernum' => '123456789']); break; case 4: //优惠券发放 $result = $MarkClass->launchcoupon($vipInfo['id'], "优惠券", "优惠券", ['starttime' => time(), 'endtime' => time(), 'coupon_name' => '满2元减1元']); break; case 5: //退款通知 $result = $MarkClass->refundsuccess($vipInfo['id'], "123456789", 1, time(), $store_id); break; case 6: //活动通知 $activity = array( 'url' => "Vip/Reward/reward_pay/merchantid/{$param['merchant_id']}/bill_order_id/1", ); $result = $MarkClass->activitySocket($param['merchant_id'], $vipInfo['openid'], 1, $activity); break; case 7: //分期到账 $install_data = array( 'store_id' => $store_id, 'type' => 7, //'分期到账', 'sendData' => array( 'aging_money' => 1, 'has_arrive' => 1, 'aging_date' => date('Y-m-d H:i:s'), 'un_arrive' => 1, ), ); $result = $MarkClass->installAccountT($install_data, $vipInfo['id'], $param['merchant_id']); break; case 8: //代金券发放 $result = $MarkClass->payCoupon($vipInfo['id'], '代金券', '代金券', ['starttime' => time(), 'endtime' => time(), 'coupon_name' => '满2元减1元']); break; case 9: //线上订单推送 $CashierModel = new RetailCashierModel(); $openid = $CashierModel->getFindField([ 'mobile'=>$param['vipPhone'], 'status' => 1 ],'openid'); $content = [ 'order_number'=>'202012122112', 'flower_balance'=>10, 'add_time'=>time(), 'pickup_type_name'=>"配送" ]; $result = $MarkClass->onlineOrderPush($param['merchant_id'],9,$content, $openid); break; } if ($result['errcode'] === 0) { return callBack(statusCode()['success'], "发送成功"); } else { return callBack(statusCode()['error'], "发送失败,请检查公众号参数" . $result['errmsg']); } } catch (\Exception $e) { return callBack(statusCode()['error'], "发送失败,请检查公众号参数"); } } /** * 商户公众号与小程序推送的参数验证 * @param $param * [ * merchant_id * type * vipPhone * ] * @return mixed */ public function pushVerify($param) { if (empty($param['merchant_id']) || empty($param['type']) || empty($param['vipPhone'])) { return callBack(statusCode()['error'], "缺少参数"); } return callBack(statusCode()['success'], "验证成功"); } }