Activity.php 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\SDK\Vod\V20170321\Models\GetAIMediaAuditJobResponseBody\mediaAuditJob\data;
  4. use app\common\model\ActivityApply;
  5. use app\common\model\ActivityApplyItem;
  6. use app\common\model\ActivityPrice;
  7. use app\common\model\ActivitySchedule;
  8. use app\common\model\ActivitySponsor;
  9. use app\common\model\ActivityTemplate;
  10. use app\common\model\ActivityTemplateItem;
  11. use app\common\model\ArticleItem;
  12. use app\common\model\BillApply;
  13. use app\common\model\BillHeader;
  14. use app\common\model\DatumUrl;
  15. use app\common\model\DeliveryAddress;
  16. use app\common\model\GoodsOrderRefund;
  17. use app\common\model\PlatformLike;
  18. use app\common\model\StoreOrderRefund;
  19. use app\common\model\TopSearch;
  20. use app\common\model\User;
  21. use app\common\model\UserCollect;
  22. use app\common\model\UserMessage;
  23. use app\common\model\UserSearch;
  24. use app\common\model\UserTrack;
  25. use app\common\model\VideoUrl;
  26. use app\common\service\CheckPower;
  27. use app\common\service\OrderCallback;
  28. use app\common\service\UserSynth;
  29. use think\Db;
  30. /**
  31. * @title 活动
  32. * @controller Activity
  33. * @group base
  34. */
  35. class Activity extends Base
  36. {
  37. // 需要登录的
  38. protected $need_login = [
  39. 'activityTags',
  40. 'activityCollect',
  41. //'activityApply',
  42. //'payApplyOrder',
  43. 'getApplyInfo',
  44. 'cancelApplyOrder',
  45. 'getMyActivityList',
  46. 'getCollectActivity',
  47. 'getActivityTrack',
  48. 'getTagsActivity',
  49. 'getApplyList',
  50. 'getTicketInfo',
  51. 'hxOrder',
  52. 'applyRefund',
  53. 'deliveryDetails',
  54. 'getBillInfo',
  55. 'getApplyOrderList',
  56. 'delApplyOrder',
  57. 'delTicket',
  58. 'unreadChange',
  59. 'getMessageList',
  60. 'batchesDel',
  61. 'applyBill',
  62. ];
  63. public function initialize()
  64. {
  65. parent::initialize();
  66. parent::setUid();
  67. }
  68. /**
  69. * @title 活动推荐
  70. * @desc 活动推荐
  71. * @author qc
  72. * @method GET
  73. * @url /api/Activity/getRecommendList
  74. * @header name:Authorization require:1 desc:Token
  75. * @param name:page type:int default:0 desc:页数
  76. * @param name:page_num type:int default:20 desc:每页数
  77. * @param name:rand_user type:string default:-- desc:随机id(非登录状态必传,page=1时生成(a123),其他页数(a123),一直查询到没有数据)
  78. * @return name:id type:string default:-- desc:资料item_id
  79. * @return name:id type:int default:-- desc:id
  80. * @return name:address type:string default:-- desc:地址
  81. * @return name:cover type:string default:-- desc:封面
  82. * @return name:label_name type:array default:-- desc:标签
  83. * @return name:start_time type:string default:-- desc:开始时间
  84. * @return name:end_time type:string default:-- desc:结束时候
  85. * @return name:status type:int default:-- desc:活动状态1正常2取消
  86. * @return name:province type:string default:-- desc:省
  87. * @return name:city type:string default:-- desc:市
  88. * @return name:county type:string default:-- desc:县区
  89. * @return name:address type:string default:-- desc:地址
  90. * @return name:is_apply type:int default:-- desc:是否报名(0否1是)
  91. * @return name:release_time type:string default:-- desc:上架时间
  92. */
  93. public function getRecommendList()
  94. {
  95. $user_id = $this->user_id ? $this->user_id : input('rand_user');
  96. if(!$user_id) $this->error('参数错误');
  97. $list = UserSynth::getRecommendList($user_id,'activity',$this->page,$this->page_num);
  98. if($list['code'] != 200) $this->error($list['msg']);
  99. $this->success('ok',$list);
  100. $search_log = UserSearch::getSearchTitle($this->user_id,11);
  101. $search_arr = [];
  102. $where_str = 'b.id > 0';
  103. foreach ($search_log as $t){
  104. $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
  105. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  106. }
  107. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  108. $field = 'a.id,cover,a.user_id,a.province,a.city,a.county,a.address,title,a.status,address,a.read_num,label,start_time,end_time,IFNULL(is_recommend,0) is_recommend ';
  109. $table = 'dd_activity';
  110. $order_by_two = 'a.read_num';
  111. $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
  112. $sql2 = "SELECT count(a.id) num FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id WHERE a.is_deleted = 0 AND a.status = 1 ";
  113. $list = Db::query($sql);
  114. $list = dispose_recommend($list);
  115. array_walk($list,function (&$v,$k){
  116. $v['read_num'] = numTransform( $v['read_num']);
  117. $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
  118. $v['cover'] = $v['cover_arr'] ? $v['cover_arr'][0]:null;
  119. $v['is_apply'] = ActivityApply::checkApply($this->user_id,$v['id']);
  120. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  121. });
  122. $total = Db::query($sql2);
  123. $this->success('ok',['list'=>$list,'total_count'=>$total[0]['num'],'page_num'=>$this->page_num]);
  124. }
  125. /**
  126. * @title 活动列表
  127. * @desc 活动列表
  128. * @author qc
  129. * @method GET
  130. * @url /api/Activity/getActivityList
  131. * @header name:Authorization require:1 desc:Token
  132. * @param name:page type:int default:0 desc:页数
  133. * @param name:page_num type:int default:20 desc:每页数
  134. * @param name:sel_type type:int default:0 desc:活动状态【0全部,1已结束2待开始3进行中】
  135. * @return name:title type:string default:-- desc:标题
  136. * @return name:cover type:string default:-- desc:海报
  137. * @return name:start_time type:string default:-- desc:开始时间
  138. * @return name:end_time type:string default:-- desc:结束时间
  139. * @return name:province type:string default:-- desc:省
  140. * @return name:city type:string default:-- desc:市
  141. * @return name:county type:string default:-- desc:县区
  142. * @return name:address type:string default:-- desc:地址
  143. */
  144. public function getActivityList(){
  145. $sort_type = input('get.sort_type',1);
  146. $sel_type = input('get.sel_type',0);
  147. switch ($sort_type) {
  148. case 1:
  149. $order = ['read_num'=>'desc','id'=>'asc'];
  150. break;
  151. case 2:
  152. $order = ['id'=>'asc','sort'=>'desc'];
  153. break;
  154. case 3:
  155. $order = ['id'=>'desc','sort'=>'desc'];
  156. break;
  157. }
  158. $where = [];
  159. $where[] = ['is_deleted','=',0];
  160. $where[] = ['status','=',1];
  161. $where[] = ['release_time','< time',date('Y-m-d H:i:s')];
  162. switch ($sel_type) {
  163. case 1:
  164. $where[] = ['end_time','< time',date('Y-m-d H:i:s')];
  165. break;
  166. case 2:
  167. $where[] = ['start_time','> time',date('Y-m-d H:i:s')];
  168. break;
  169. case 3:
  170. $where[] = ['start_time','< time',date('Y-m-d H:i:s')];
  171. $where[] = ['end_time','> time',date('Y-m-d H:i:s')];
  172. break;
  173. }
  174. $list = \app\common\model\Activity::field('id,title,cover,start_time,end_time,province,city,county,address,read_num,release_time')
  175. ->where($where)->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
  176. foreach ($list as $k => $v){
  177. $user = User::where('id',$v['id'])->field('id,name,headimg')->find();
  178. if($user){
  179. $list[$k]['name'] = $user['name'];
  180. $list[$k]['headimg'] = $user['headimg'];
  181. }else{
  182. $list[$k]['name'] = null;
  183. $list[$k]['headimg'] = null;
  184. }
  185. }
  186. $total_num = \app\common\model\Activity::where($where)->count();
  187. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  188. }
  189. /**
  190. * @title 获取活动详情
  191. * @desc 获取活动详情
  192. * @author qc
  193. * @method GET
  194. * @url /api/Activity/getActivityDetail
  195. * @header name:Authorization require:1 desc:Token
  196. * @param name:id type:int default:-- desc:活动id
  197. * @return name:title type:string default:-- desc:标题
  198. * @return name:cover type:string default:-- desc:图片
  199. * @return name:content type:string default:-- desc:详情
  200. * @return name:create_at type:string default:-- desc:时间
  201. * @return name:start_time type:string default:-- desc:开始时间
  202. * @return name:end_time type:string default:-- desc:结束时间
  203. * @return name:province type:string default:-- desc:省
  204. * @return name:city type:string default:-- desc:市
  205. * @return name:county type:string default:-- desc:县区
  206. * @return name:address type:string default:-- desc:地址
  207. * @return name:longitude type:string default:-- desc:经度
  208. * @return name:latitude type:string default:-- desc:纬度
  209. * @return name:label type:string default:-- desc:标签[多个','隔开]
  210. * @return name:label_name type:array default:-- desc:标签[数组]
  211. * @return name:is_apply type:int default:0 desc:是否报名【0否1是】
  212. * @return name:praise_num type:int default:-- desc:点赞量
  213. * @return name:is_praise type:int default:-- desc:是否点赞【0否1是】
  214. * @return name:is_collect type:int default:-- desc:是否收藏【0否1是】
  215. * @return name:collect_num type:int default:-- desc:收藏量
  216. * @return name:transmit_num type:int default:-- desc:转发量
  217. * @return name:pay_offline type:int default:-- desc:是否支持下线支付【0否1是】
  218. * @return name:app_name type:string default:-- desc:发布方名称
  219. * @return name:app_logo type:string default:-- desc:发布方头像
  220. * @return name:read_num type:string default:-- desc:阅读量
  221. * @return name:release_time type:string default:-- desc:发布时间
  222. * @return name:offline_user type:string default:-- desc:线下支付户名
  223. * @return name:offline_bank type:string default:-- desc:线下支付开户行
  224. * @return name:offline_card type:string default:-- desc:线下支付账号
  225. * @return name:video_id type:int default:-- desc:视频系列id
  226. * @return name:video_item type:int default:-- desc:关联视频详情id【video_arr.id】
  227. * @return name:video_jump type:int default:-- desc:关联视频是否能跳转【0不能跳转,1能跳转,验证是否vip】
  228. *
  229. * @return name:article_id type:int default:-- desc:图文系列id
  230. * @return name:article_item type:int default:-- desc:关联图文详情id【item_list.id】
  231. * @return name:article_jump type:int default:-- desc:关联图文是否能跳转【0不能跳转,1能跳转,验证是否vip】
  232. * @return name:datum_id type:int default:-- desc:资料id--ppt【系列id】
  233. * @return name:datum_item type:int default:-- desc:资料id--ppt【系列下的其中一个】
  234. * @return name:datum_jump type:int default:-- desc:关联资料是否能跳转【0不能跳转,1能跳转,验证是否vip】
  235. * @return name:datum_url type:int default:-- desc:关联资料链接
  236. *
  237. * @return name:price_list type:array default:-- desc:价格设置
  238. * @return name:price_list.id type:int default:-- desc:价格阶梯记录id
  239. * @return name:price_list.ladder_title type:string default:-- desc:标题
  240. * @return name:price_list.ladder_remark type:string default:-- desc:备注
  241. * @return name:price_list.ladder_price type:float default:-- desc:价格
  242. * @return name:price_list.ladder_status type:float default:-- desc:当前门票是否下架【0下架,1正常】
  243. * @return name:price_list.ladder_num type:float default:-- desc:活动票发行量
  244. * @return name:price_list.stock type:int default:-- desc:剩余票量
  245. * @return name:price_list.fill_num type:int default:-- desc:满减张数
  246. * @return name:price_list.sub_money type:float default:-- desc:每张优惠
  247. * @return name:price_list.is_sh type:int default:-- desc:是否需要审核【1是,0否】
  248. * @return name:sponsor type:array default:-- desc:主办方信息
  249. * @return name:sponsor.id type:int default:-- desc:主办方记录id
  250. * @return name:sponsor.qr_code type:string default:-- desc:二维码
  251. * @return name:sponsor.cover type:string default:-- desc:主办方logo
  252. * @return name:sponsor.official_web type:string default:-- desc:主办方官网
  253. * @return name:sponsor.title type:string default:-- desc:主办方名称
  254. * @return name:sponsor.address type:string default:-- desc:地址
  255. * @return name:sponsor.email type:string default:-- desc:email
  256. * @return name:sponsor.phone type:string default:-- desc:phone
  257. * @return name:template_list type:array default:-- desc:报名模板信息
  258. * @return name:template_list.id type:int default:-- desc:报名模板详情id
  259. * @return name:template_list.title type:string default:-- desc:标题
  260. * @return name:template_list.type type:string default:-- desc:类型【1input,2文本,3多选】
  261. * @return name:template_list.value type:string default:-- desc:报名提交填写的内容【1input,2文本】
  262. * @return name:template_list.required type:int default:-- desc:是否必填【1是,0否】
  263. * @return name:template_list.extend type:array default:-- desc:多选选项【type=3】
  264. * @return name:template_list.extend.item_title type:string default:-- desc:选项【type=3】
  265. *
  266. * @return name:schedule type:array default:-- desc:活动日程
  267. * @return name:schedule.title type:string default:-- desc:标题
  268. * @return name:schedule.date_time type:string default:-- desc:时间
  269. * @return name:schedule.schedule_list type:array default:-- desc:日程详情
  270. * @return name:schedule.schedule_list.theme type:string default:-- desc:主题
  271. * @return name:schedule.schedule_list.theme_time type:string default:-- desc:主题时间
  272. * @return name:schedule.children type:array default:-- desc:二级日程【数据同上】
  273. *
  274. */
  275. public function getActivityDetail()
  276. {
  277. $sel_where[] = ['id','=',input('get.id')];
  278. $detail = \app\common\model\Activity::where($sel_where)
  279. ->with(['sponsor','priceList'])
  280. ->find()->toArray();
  281. if($detail['is_deleted'] != 0 || $detail['status'] !=1) $this->error('该活动已取消');
  282. $detail['cover_arr'] = $detail['cover'] ? explode('|',$detail['cover']) : null;
  283. $detail['label_name'] = $detail['label'] ? explode(',',trim($detail['label'],',')): null;
  284. $detail['is_apply'] = ActivityApply::checkApply($this->user_id,$detail['id']);
  285. $detail['is_praise'] = PlatformLike::checkTags($this->user_id,$detail['id'],4);
  286. $detail['praise_num'] = PlatformLike::getPraiseNum($detail['id'],4);
  287. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,7,$detail['id']);
  288. $detail['collect_num'] = UserCollect::getCollectNum(7,$detail['id']);
  289. $detail['transmit_num'] = numTransform($detail['transmit_num']);
  290. $detail['read_num'] = numTransform($detail['read_num']);
  291. $detail['article_jump'] = ArticleItem::checkVip($detail['article_item'],$this->user_id);
  292. $detail['video_jump'] = VideoUrl::checkVip($detail['video_item'],$this->user_id);
  293. $detail['datum_jump'] = DatumUrl::checkVip($detail['datum_item'],$this->user_id);
  294. $auth_info = \app\common\model\Activity::getAuth($detail['user_id'],APPNAME,APPLOGO);
  295. $detail['app_name'] = $auth_info['app_name'];
  296. $detail['app_logo'] = $auth_info['app_logo'];
  297. $template_list = ActivityTemplateItem::getList($detail['template_id']);
  298. array_walk($template_list,function (&$v){
  299. if($v['type'] == 3 && $v['extend'] )$v['extend'] = json_decode($v['extend']);
  300. });
  301. $detail['template_list'] =$template_list;
  302. $detail['schedule'] = ActivitySchedule::getActivitySchedule($detail['id']);
  303. \app\common\model\Activity::where('id',$detail['id'])->setInc('read_num');
  304. UserTrack::crateTrack($this->user_id,7,input('get.id'),0);
  305. // TopSearch::seIncHotNum($detail['id'],$this->request->controller());
  306. if($this->user_id){
  307. TopSearch::seIncHotNum($detail['id'],$this->request->controller());
  308. }
  309. if($this->user_id){
  310. $General = new General();
  311. $General->label($detail['label']);
  312. }
  313. $this->success('ok',['detail'=>$detail]);
  314. }
  315. /**
  316. * @title 活动详情--返回字段少[活动报名]
  317. * @desc 活动详情
  318. * @author qc
  319. * @method GET
  320. * @url /api/Activity/getActivityDetailSimplify
  321. * @header name:Authorization require:1 desc:Token
  322. * @param name:id type:int default:-- desc:活动id
  323. * @return name:title type:string default:-- desc:标题
  324. * @return name:cover type:string default:-- desc:图片
  325. * @return name:create_at type:string default:-- desc:时间
  326. * @return name:start_time type:string default:-- desc:开始时间
  327. * @return name:end_time type:string default:-- desc:结束时间
  328. * @return name:pay_offline type:int default:-- desc:是否支持下线支付【0否1是】
  329. * @return name:province type:string default:-- desc:省
  330. * @return name:city type:string default:-- desc:市
  331. * @return name:county type:string default:-- desc:县区
  332. * @return name:address type:string default:-- desc:地址
  333. * @return name:release_time type:string default:-- desc:发布时间
  334. * @return name:offline_user type:string default:-- desc:线下支付户名
  335. * @return name:offline_bank type:string default:-- desc:线下支付开户行
  336. * @return name:offline_card type:string default:-- desc:线下支付账号
  337. * @return name:price_list type:array default:-- desc:价格设置
  338. * @return name:price_list.id type:int default:-- desc:价格阶梯记录id
  339. * @return name:price_list.ladder_title type:string default:-- desc:标题
  340. * @return name:price_list.ladder_remark type:string default:-- desc:备注
  341. * @return name:price_list.ladder_price type:float default:-- desc:价格
  342. * @return name:price_list.ladder_num type:float default:-- desc:活动票发行量
  343. * @return name:price_list.stock type:float default:-- desc:剩余票量
  344. * @return name:price_list.is_sh type:float default:-- desc:是否需要审核【1是,0否】
  345. * @return name:price_list.fill_num type:int default:-- desc:满减张数
  346. * @return name:price_list.sub_money type:float default:-- desc:每张优惠
  347. * @return name:sponsor type:array default:-- desc:主办方信息
  348. * @return name:sponsor.id type:int default:-- desc:主办方记录id
  349. * @return name:sponsor.qr_code type:string default:-- desc:二维码
  350. * @return name:sponsor.cover type:string default:-- desc:主办方logo
  351. * @return name:sponsor.official_web type:string default:-- desc:主办方官网
  352. * @return name:sponsor.title type:string default:-- desc:主办方名称
  353. * @return name:sponsor.address type:string default:-- desc:地址
  354. * @return name:sponsor.email type:string default:-- desc:email
  355. * @return name:sponsor.phone type:string default:-- desc:phone
  356. * @return name:template_list type:array default:-- desc:报名模板信息
  357. * @return name:template_list.id type:int default:-- desc:报名模板详情id
  358. * @return name:template_list.title type:string default:-- desc:标题
  359. * @return name:template_list.type type:string default:-- desc:类型【1input,2文本,3多选】
  360. * @return name:template_list.value type:string default:-- desc:报名提交填写的内容【1input,2文本】
  361. * @return name:template_list.required type:int default:-- desc:是否必填【1是,0否】
  362. * @return name:template_list.extend type:array default:-- desc:多选选项【type=3】
  363. * @return name:template_list.extend.item_title type:string default:-- desc:选项【type=3】
  364. */
  365. public function getActivityDetailSimplify()
  366. {
  367. $sel_where[] = ['id','=',input('get.id')];
  368. $detail = \app\common\model\Activity::where($sel_where)
  369. ->field('id,sponsor_id,title,cover,create_at,start_time,end_time,province,city,county,address,template_id,pay_offline,offline_user,offline_bank,offline_card')
  370. ->with(['sponsor','priceList'])
  371. ->find()->toArray();
  372. $template_list = ActivityTemplateItem::getList($detail['template_id']);
  373. array_walk($template_list,function (&$v){
  374. if($v['type'] == 3 && $v['extend'] )$v['extend'] = json_decode($v['extend']);
  375. });
  376. $detail['template_list'] =$template_list;
  377. $this->success('ok',['detail'=>$detail]);
  378. }
  379. /**
  380. * @title 点赞||取消点赞
  381. * @desc 点赞||取消点赞
  382. * @author qc
  383. * @method POST
  384. * @url /api/Activity/activityTags
  385. * @header name:Authorization require:1 desc:Token
  386. * @param name:id type:int default:1 desc:活动id
  387. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  388. */
  389. public function activityTags()
  390. {
  391. $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),4);
  392. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  393. }
  394. /**
  395. * @title 收藏||取消收藏
  396. * @desc 用户收藏
  397. * @author qc
  398. * @method POST
  399. * @url /api/Activity/activityCollect
  400. * @header name:Authorization require:1 desc:Token
  401. * @param name:id type:int require:1 default:-- desc:活动id
  402. * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
  403. */
  404. public function activityCollect(){
  405. $coll_status = UserCollect::plateCollect($this->user_id,7,input('post.id',0));
  406. $coll_status ? $this->success('收藏成功',['status'=>1]) : $this->success('取消收藏成功',['status'=>0]);
  407. }
  408. /**
  409. * @title 活动转发(转发数量统计)
  410. * @desc 转发成功后调用
  411. * @author qc
  412. * @method POST
  413. * @url /api/Activity/activityTransmit
  414. * @header name:Authorization require:1 desc:Token
  415. * @param name:id type:int default:-- desc:活动id
  416. */
  417. public function activityTransmit()
  418. {
  419. $activity_id = input('post.id',0);
  420. \app\common\model\Activity::where('id',$activity_id)->setInc('transmit_num');
  421. $this->success('ok');
  422. }
  423. /**
  424. * @title 获取报名实例
  425. * @desc 获取报名实例
  426. * @author qc
  427. * @method GET
  428. * @url /api/Activity/getApplyData
  429. * @header name:Authorization require:1 desc:Token
  430. * @param name:id type:int default:-- desc:活动id
  431. */
  432. public function getApplyData()
  433. {
  434. $sel_where[] = ['id','=',input('get.id')];
  435. $detail = \app\common\model\Activity::where($sel_where)
  436. ->field('id,sponsor_id,title,cover,create_at,start_time,end_time,province,city,county,address,template_id')
  437. ->with(['sponsor','priceList'])
  438. ->find()->toArray();
  439. $template_list = ActivityTemplateItem::getList($detail['template_id']);
  440. $user_info = $this->userInfo();
  441. $apply_data = [];
  442. array_walk($template_list,function (&$v)use ($user_info){
  443. if(in_array($v['type'],[1,2])) $v['value'] = '填写'.$v['title'];
  444. if($v['type'] == 3 && $v['extend'] ) {
  445. $extend = json_decode($v['extend'],true);
  446. foreach ($extend as &$ev) {
  447. $ev['value'] = 1;
  448. }
  449. $v['extend'] =$extend;
  450. }
  451. });
  452. $apply_data[] = [
  453. 'price_id' => $detail['price_list'][0]['id'],
  454. 'name' => $user_info['name'],
  455. 'phone_pre' => $user_info['phone_pre'],
  456. 'phone' => $user_info['phone'],
  457. 'email' => '123456@qq.com',
  458. 'num' => 1,
  459. 'code' => 1,
  460. 'phone_code' => 123456,
  461. 'template_list' => $template_list,
  462. ];
  463. $apply_data[] = [
  464. 'price_id' => $detail['price_list'][0]['id'],
  465. 'name' => $user_info['name'],
  466. 'phone_pre' => $user_info['phone_pre'],
  467. 'phone' => $user_info['phone'],
  468. 'email' => '123456@qq.com',
  469. 'num' => 1,
  470. 'code' => 1,
  471. 'phone_code' => 123456,
  472. 'template_list' => $template_list,
  473. ];
  474. $bill_info = BillHeader::where('id',1)->field('type,header,identify_number,bank,card_no,phone,email,address,remark')->find()->toArray();
  475. $this->success('ok',[
  476. 'apply_json'=>json_encode($apply_data,JSON_UNESCAPED_UNICODE),
  477. 'apply_array'=>$apply_data,
  478. 'template_json'=>json_encode($template_list,JSON_UNESCAPED_UNICODE),
  479. 'bill_info'=>json_encode($bill_info,JSON_UNESCAPED_UNICODE),
  480. ]);
  481. }
  482. /**
  483. * @title 活动报名【生成订单】
  484. * @desc 活动报名[生成订单(报名记录),返回支付信息]
  485. * @author qc
  486. * @method POST
  487. * @url /api/Activity/activityApply
  488. * @header name:Authorization require:1 desc:Token
  489. * @param name:act_id type:int default:-- desc:活动id
  490. * @param name:tg type:string default:-- desc:推广参数
  491. * @param name:phone type:int default:-- desc:下单人手机号【未登录必填】
  492. * @param name:phone_pre type:string default:-- desc:下单人手机号前缀【未登录必填】
  493. * @param name:phone_code type:string default:-- desc:下单人手机号验证码【未登录必填】
  494. * @param name:pay_type type:int require:1 default:0 desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付,6微信pc,7pc支付宝,9线下支付)
  495. * @param name:apply_data type:string default:-- desc:报名信息
  496. * @param name:apply_data.price_id type:int default:-- desc:价格id
  497. * @param name:apply_data.name type:string default:-- desc:联系人
  498. * @param name:apply_data.phone_pre type:string default:-- desc:手机号前缀
  499. * @param name:apply_data.phone type:string default:-- desc:联系人电话
  500. * @param name:apply_data.email type:string default:-- desc:email
  501. * @param name:apply_data.num type:int default:-- desc:数量
  502. * @param name:apply_data.code type:int default:-- desc:第几张票
  503. * @param name:apply_data.phone_code type:int default:-- desc:短信验证码
  504. * @param name:apply_data.template_list type:string default:-- desc:报名模板信息【活动模板填完值之后的json】
  505. * @param name:bill_info type:string default:-- desc:发票信息--json【不开票可以不传】
  506. * @param name:bill_info.type type:int default:-- desc:类型id
  507. * @param name:bill_info.header type:string default:-- desc:抬头名称[公司名称||个人名称]
  508. * @param name:bill_info.identify_number type:string default:-- desc:纳税人识别号
  509. * @param name:bill_info.email type:string default:-- desc:邮箱
  510. * @param name:bill_info.remark type:string default:-- desc:备注
  511. *
  512. * @param name:address_info type:string default:-- desc:收货信息--json【非物流不传】
  513. * @param name:address_info.type type:int require:1 default:-- desc:领取方式【1现场2快递】
  514. * @param name:address_info.send_type type:int require:1 default:-- desc:申请类型【1点子发票2纸质发票】
  515. * @param name:address_info.pro_name type:string require:1 default:-- desc:省名【快递必传】
  516. * @param name:address_info.city_name type:string require:1 default:-- desc:市名【快递必传】
  517. * @param name:address_info.county_name type:string require:1 default:-- desc:县区名【快递必传】
  518. * @param name:address_info.detail type:string require:0 default:-- desc:详细地址【快递必传】
  519. * @param name:address_info.phone type:string require:1 default:-- desc:联系电话【快递必传】
  520. * @param name:address_info.name type:string require:1 default:-- desc:联系人【快递必传】
  521. *
  522. * @return name:pay_status type:int default:0 desc:该值为1:订单金额是0不需要支付!!!
  523. * @return name:config type:array default:0 desc:支付配置
  524. * @return name:config.appId type:string default:-- desc:公众账号ID
  525. * @return name:config.signType type:string default:-- desc:签名类型
  526. *
  527. * @return name:config.appId type:string default:-- desc:appID【h5】
  528. * @return name:config.paySign type:string default:-- desc:签名【h5】
  529. * @return name:config.nonceStr type:string default:-- desc:随机字符串【h5】
  530. * @return name:config.timeStamp type:string default:-- desc:时间戳【h5】
  531. * @return name:config.appid type:string default:-- desc:appid【微信APP】
  532. * @return name:config.sign type:string default:-- desc:签名【微信APP】
  533. * @return name:config.noncestr type:string default:-- desc:随机字符串【微信APP】
  534. * @return name:config.timestamp type:string default:-- desc:时间戳【微信APP】
  535. *
  536. * @return name:config.partnerid type:string default:-- desc:商户号
  537. * @return name:config.prepayid type:string default:-- desc:唯一支付号
  538. *
  539. * @return name:config.package type:string default:-- desc:package
  540. * @return name:config.mch_id type:string default:-- desc:商户号(H5)
  541. * @return name:config.pay_no type:string default:-- desc:订单支付号(H5)
  542. * @return name:config.notify_url type:string default:-- desc:回调地址(H5)
  543. * @return name:config.total_fee type:int default:-- desc:支付金额(分!!!)
  544. * @return name:code_url type:string default:-- desc:付款码url
  545. * @return name:openid type:string default:-- desc:openid
  546. *
  547. */
  548. public function activityApply()
  549. {
  550. $act_id = input('post.act_id');
  551. $tg = input('post.tg','');
  552. $pay_type = input('post.pay_type',1);
  553. $act_info = \app\common\model\Activity::where('id',$act_id)->where('is_deleted',0)->find();
  554. if(!$act_info) $this->error('活动不存在');
  555. if(strtotime($act_info->end_time) < time() ) $this->error('活动已经结束');
  556. if(strtotime($act_info->start_time) < time() ) $this->error('活动已经开始');
  557. if($act_info->status == 2) $this->error('活动已经取消');
  558. if($act_info->status == 0) $this->error('活动已经下架');
  559. if($act_info->pay_offline == 0 && $pay_type == 9) $this->error('活动不支持线下支付');
  560. if(!$this->user_id) {
  561. $phone = input('post.phone');
  562. $phone_pre = input('post.phone_pre','86');
  563. $phone_code = input('post.phone_code');
  564. if(empty($phone)) $this->error('请填写支付人手机号'.$phone);
  565. if(empty($phone_code)) $this->error('请填写支付人手机号验证码:'.$phone_code);
  566. $check_code = $this->checkPhoneCode($phone,$phone_code,$phone_pre);
  567. if(!$check_code) $this->error('验证码错误');
  568. $this->updatePhoneCode($check_code);
  569. $user_info = User::getUserInfo($phone,$phone_pre);
  570. $this->user_id = $user_info['id'];
  571. if(empty($user_info)) $this->error('该手机号被禁用');
  572. }else{
  573. $user_info = $this->userInfo();
  574. }
  575. // 订单详情
  576. $apply_info = [
  577. 'user_id' => $this->user_id,
  578. 'order_no' => get_order_sn(),
  579. 'pay_no' => get_order_sn(),
  580. 'name' => $user_info['name'],
  581. 'phone' => $user_info['phone'],
  582. 'phone_pre' => $user_info['phone_pre'],
  583. 'pay_type' => $pay_type,
  584. 'act_id' => $act_id,
  585. 'tg_id' => $tg ? Db::name('activity_qrcode')->where('tg_param',$tg)->max('id'): 0,
  586. ];
  587. $apply_item = [];
  588. $post_apply = input('post.apply_data');
  589. $post_bill = input('post.bill_info');
  590. $post_address = input('post.address_info');
  591. $apply_data = json_decode(stripslashes($post_apply),true);
  592. $bill_info = json_decode(stripslashes($post_bill),true);
  593. $address_info = json_decode(stripslashes($post_address),true);
  594. if(empty($apply_data)) $this->error('请填写报名信息');
  595. $ret_data = ['pay_status'=>0,'config'=>null,'code_url'=>'','openid'=>$user_info['openid'],'order_id'=>0];
  596. Db::startTrans();
  597. try {
  598. $cl_apply = [];
  599. array_walk($apply_data,function (&$cv)use (&$cl_apply){
  600. if(isset($cl_apply[$cv['price_id']])){
  601. $cl_apply[$cv['price_id']]++;
  602. } else{
  603. $cl_apply[$cv['price_id']] = 1;
  604. }
  605. });
  606. array_walk($apply_data,function (&$v)use (&$apply_item,$act_id,$cl_apply){
  607. $v['buy_total'] = $cl_apply[$v['price_id']];
  608. // 验证码验证
  609. //$check_code = $this->checkPhoneCode($v['phone'],$v['phone_code'],$v['phone_pre']);
  610. // if(!$check_code) $this->exception($v['phone'].'验证码错误');
  611. //$this->updatePhoneCode($check_code);
  612. // 会员验证
  613. $user_item = User::getUserInfo($v['phone'],$v['phone_pre'] ? $v['phone_pre'] : 86);
  614. if(empty($user_item)) $this->exception($v['phone'].'被禁用');
  615. // 售票验证
  616. // var_dump($v['price_id']);
  617. $price_info = ActivityPrice::where('id',$v['price_id'])->find()->toArray();
  618. if($price_info['ladder_status'] != 1) $this->exception($price_info['ladder_title'].'已下架');
  619. if($price_info['stock'] <= 0) $this->exception($price_info['ladder_title'].'已售罄');
  620. // 扣减库存
  621. ActivityPrice::where('id',$price_info['id'])->setDec('stock',$v['num']);
  622. // var_dump($v['template_list']);
  623. // 报名模板验证
  624. foreach ($v['template_list'] as &$tv) {
  625. if($tv['required'] && in_array($tv['type'],[1,2]) && !$tv['value'] ) $this->exception($tv['title'].'必填');
  626. if($tv['required'] && in_array($tv['type'],[3])) {
  627. $extend = is_array($tv['extend']) ? $tv['extend'] : json_decode($tv['extend']);
  628. $sel_extend = array_sum(array_column($extend,'value'));
  629. if(!$sel_extend) $this->exception($tv['title'].'必选');
  630. }
  631. }
  632. // 票详情
  633. $apply_item[] = [
  634. 'user_id' => $user_item['id'],
  635. 'act_id' => $act_id,
  636. 'price_id' => $v['price_id'],
  637. 'num' => $v['num'],
  638. 'name' => $v['name'],
  639. 'phone' => $v['phone'],
  640. 'code' => isset($v['code']) ? $v['code'] : 1,
  641. 'email' => $v['email'],
  642. 'sh_status' => $price_info['is_sh'] ? 0 : 1 ,
  643. 'price_sh' => $price_info['is_sh'] ,
  644. 'money' => $price_info['fill_num'] > 0 && $v['buy_total'] >= $price_info['fill_num'] ? bcmul($price_info['ladder_price']- $price_info['sub_money'],$v['num'],2) : bcmul($price_info['ladder_price'],$v['num'],2),
  645. 'total_money' => bcmul($price_info['ladder_price'],$v['num'],2),
  646. 'extend' => json_encode($v['template_list'],JSON_UNESCAPED_UNICODE),
  647. ];
  648. });
  649. $apply_info['money'] = array_sum(array_column($apply_item,'money'));
  650. $apply_info['total_money'] = array_sum(array_column($apply_item,'total_money'));
  651. $apply_info['num'] = array_sum(array_column($apply_item,'num'));
  652. if($apply_info['money'] < 0) $this->exception('金额错误');
  653. // 主订单写入
  654. $order_info = ActivityApply::create($apply_info)->toArray();
  655. array_walk($apply_item,function (&$v)use ($order_info){
  656. $v['apply_id'] = $order_info['id'];
  657. });
  658. (new ActivityApplyItem())->saveAll($apply_item);
  659. if($order_info['money'] == 0) {
  660. $back_res = OrderCallback::activityOrderCallBack($order_info);// 支付完成后回调
  661. if(!$back_res['ret_val']) $this->exception($back_res['msg']);
  662. $ret_data['pay_status'] = 1;
  663. }else{
  664. $ret_data['order_id'] = $order_info['id'];
  665. switch ($pay_type){
  666. case 1:
  667. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  668. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'MWEB');
  669. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  670. $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
  671. $pay_config['config']['pay_no'] = $order_info['pay_no'];
  672. $pay_config['config']['notify_url'] = $notify_url;
  673. $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
  674. $pay_config['config']['total_fee'] = $order_info['money'] * 100;
  675. $ret_data['config'] = $pay_config['config'];
  676. break;
  677. case 2:
  678. $notify_url = $this->request->root(true) . '/api/Alipay/applyOrderNotify';
  679. $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
  680. $config = Alipay::ali_pay_h5('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,$return_url);
  681. $ret_data['config']['ali_url'] = $config;
  682. $ret_data['ali_url'] = $config;
  683. break;
  684. case 3:
  685. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  686. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'APP');
  687. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  688. $ret_data['config'] = $pay_config['config'];
  689. break;
  690. case 4:
  691. $notify_url = $this->request->root(true) . '/api/Alipay/applyOrderNotify';
  692. $config = Alipay::ali_pay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url);
  693. $ret_data['config']['ali_url'] = $config;
  694. $ret_data['ali_url'] = $config;
  695. $ret_data['money'] = $order_info['money'];
  696. break;
  697. case 5 :
  698. if(!$user_info['openid']) $this->exception('请绑定openid');
  699. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  700. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'JSAPI',$user_info['openid']);
  701. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  702. $ret_data['config'] = $pay_config['config'];
  703. break;
  704. case 6:
  705. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  706. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'] ,$notify_url,'NATIVE');
  707. $ret_data['config'] = $pay_config['config'];
  708. $ret_data['code_url'] = $pay_config['pc_pay_url'];
  709. break;
  710. case 7:
  711. $notify_url = $this->request->root(true) . '/api/Alipay/applyOrderNotify';
  712. $return_url ='https://'.$_SERVER['HTTP_HOST']."/pc/?#/activity/my-order#";
  713. $config = Alipay::ali_pay_pc('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,$return_url);
  714. $ret_data['config']['ali_url'] = $config;
  715. $ret_data['ali_url'] = $config;
  716. break;
  717. }
  718. }
  719. //订单需要开票
  720. if($order_info['money'] > 0 && !empty($bill_info)) {
  721. // 是否是选择的已有的抬头
  722. /* if(isset($bill_info['header_id']) && $bill_info['header_id']) {
  723. $bill_info = BillHeader::where('id',$bill_info['header_id'])->find()->toArray();
  724. }else{
  725. $bill_info = BillHeader::saveHeader(array_merge($bill_info,['user_id'=>$user_info['id'],'is_deleted'=>1]));
  726. }*/
  727. // 是否有物流地址
  728. $address_id = 0;
  729. if(!empty($address_info) && isset($address_info['send_type']) && $address_info['send_type'] == 2 && isset($address_info['type']) && $address_info['type']){
  730. $address_info = DeliveryAddress::saveAddress(array_merge($address_info,['user_id'=>$user_info['id'],'is_deleted'=>1]));
  731. $address_id = $address_info['id'];
  732. }
  733. $ret_val = UserSynth::buildBillApply($user_info['id'], $order_info['id'], 3,$bill_info,$address_id,1,$bill_info['remark'],0);
  734. if($ret_val['code'] != 200) $this->exception($ret_val['msg']);
  735. }
  736. Db::commit();
  737. }catch (\Exception $e) {
  738. Db::rollback();
  739. $this->error($e->getMessage());
  740. }
  741. $this->success('报名成功',$ret_data);
  742. }
  743. /**
  744. * @title 活动报名订单支付
  745. * @desc 活动报名订单支付
  746. * @author qc
  747. * @method POST
  748. * @url /api/Activity/payApplyOrder
  749. * @header name:Authorization require:1 desc:Token
  750. * @param name:order_id type:int default:-- desc:订单id【报名记录id】
  751. * @param name:pay_type type:int default:-- desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付,9线下支付)
  752. *
  753. * @return name:config type:array default:0 desc:支付配置
  754. * @return name:config.appId type:string default:-- desc:公众账号ID
  755. * @return name:config.signType type:string default:-- desc:签名类型
  756. * @return name:config.paySign type:string default:-- desc:签名
  757. * @return name:config.nonceStr type:string default:-- desc:随机字符串
  758. * @return name:config.timestamp type:string default:-- desc:时间戳
  759. * @return name:config.partnerid type:string default:-- desc:商户号
  760. * @return name:config.prepayid type:string default:-- desc:唯一支付号
  761. * @return name:config.package type:string default:-- desc:package
  762. * @return name:config.mch_id type:string default:-- desc:商户号(H5)
  763. * @return name:config.pay_no type:string default:-- desc:订单支付号(H5)
  764. * @return name:config.notify_url type:string default:-- desc:回调地址(H5)
  765. * @return name:config.total_fee type:int default:-- desc:支付金额(分!!!)
  766. * @return name:code_url type:string default:-- desc:付款码url
  767. * @return name:openid type:string default:-- desc:openid
  768. */
  769. public function payApplyOrder()
  770. {
  771. $order_id = input('post.order_id');
  772. $order_info = ActivityApply::where('id',$order_id)->find()->toArray();
  773. if($order_info['status'] != 0) $this->error('订单状态错误');
  774. if($order_info['cancel_state'] != 0 || $order_info['is_deleted'] != 0) $this->error('订单异常');
  775. if($order_info['money'] <= 0) $this->error('订单金额错误');
  776. $pay_type = input('post.pay_type',0) ;//$order_info['pay_type'];
  777. $user_info = User::where('id',$order_info['user_id'])->find();
  778. $ret_data = ['pay_status'=>0,'config'=>[],'code_url'=>'','openid'=>$user_info['openid'],'order_id'=>0];
  779. if($pay_type == 9) $this->error('订单为线下支付,请联系管理员');
  780. Db::startTrans();
  781. try {
  782. ActivityApply::where('id',$order_id)->update(['pay_type'=>$pay_type]);
  783. switch ($pay_type){
  784. case 1:
  785. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  786. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'MWEB');
  787. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  788. $pay_config['config']['mch_id'] = config('app.wx_pay')['mch_id'];
  789. $pay_config['config']['pay_no'] = $order_info['pay_no'];
  790. $pay_config['config']['notify_url'] = $notify_url;
  791. $pay_config['config']['mweb_url'] = $pay_config['mweb_url'];
  792. $pay_config['config']['total_fee'] = $order_info['money'] * 100;
  793. $ret_data['config'] = $pay_config['config'];
  794. break;
  795. case 2:
  796. $notify_url = $this->request->root(true) . '/api/Alipay/applyOrderNotify';
  797. $return_url ='https://'.$_SERVER['HTTP_HOST']."/dist/#/my";
  798. $config = Alipay::ali_pay_h5('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,$return_url);
  799. $ret_data['config']['ali_url'] = $config;
  800. $ret_data['ali_url'] = $config;
  801. break;
  802. case 3:
  803. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  804. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'APP');
  805. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  806. $ret_data['config'] = $pay_config['config'];
  807. break;
  808. case 4:
  809. $notify_url = $this->request->root(true) . '/api/Alipay/LevelOrderNotify';
  810. $config = Alipay::ali_pay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url);
  811. $ret_data['config']['ali_url'] = $config;
  812. $ret_data['ali_url'] = $config;
  813. $ret_data['money'] = $order_info['money'];
  814. break;
  815. case 5 :
  816. if(!$user_info['openid']) $this->exception('请绑定openid');
  817. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  818. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,'JSAPI',$user_info['openid']);
  819. if($pay_config['code'] != 200) $this->exception($pay_config['msg']);
  820. $ret_data['config'] = $pay_config['config'];
  821. break;
  822. case 6 :
  823. $notify_url = $this->request->root(true) . '/api/we_chat_pay/applyOrderNotify';
  824. $pay_config = WeChatPay::wxPay('订单支付',$order_info['pay_no'],$order_info['money'] ,$notify_url,'NATIVE');
  825. $ret_data['config'] = $pay_config['config'];
  826. $ret_data['code_url'] = $pay_config['pc_pay_url'];
  827. break;
  828. case 7 :
  829. $notify_url = $this->request->root(true) . '/api/Alipay/applyOrderNotify';
  830. $return_url ='https://'.$_SERVER['HTTP_HOST']."/pc/?#/activity/my-order#";
  831. $config = Alipay::ali_pay_pc('订单支付',$order_info['pay_no'],$order_info['money'],$notify_url,$return_url);
  832. $ret_data['config']['ali_url'] = $config;
  833. $ret_data['ali_url'] = $config;
  834. break;
  835. }
  836. Db::commit();
  837. }catch (\Exception $e){
  838. Db::rollback();
  839. $this->error($e->getMessage());
  840. }
  841. $this->success('ok',$ret_data);
  842. }
  843. /**
  844. * @title 报名详情【订单详情】
  845. * @desc 报名详情
  846. * @author qc
  847. * @method GET
  848. * @url /api/Activity/getApplyInfo
  849. * @header name:Authorization require:1 desc:Token
  850. * @param name:id type:int default:-- desc:订单id
  851. * @param name:order_no type:string default:-- desc:订单号
  852. * @param name:pay_no type:string default:-- desc:订单支付号
  853. * @param name:create_at type:string default:-- desc:创建时间
  854. * @param name:pay_at type:string default:-- desc:支付时间
  855. * @param name:status type:int default:-- desc:订单状态【0未支付1已支付2已取消】
  856. * @param name:money type:float default:-- desc:订单金额
  857. * @param name:pay_type type:int default:-- desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付,9线下支付)
  858. * @param name:pay_state type:int default:-- desc:是否支付【0未支付1已支付】
  859. * @param name:cancel_state type:int default:-- desc:是否取消【0未取消1已取消】
  860. * @param name:refund_state type:int default:-- desc:退款状态(0未申请1审核中2同意3拒绝4退款成功5退款异常)
  861. * @param name:phone_pre type:string default:-- desc:phone前缀
  862. * @param name:phone type:string default:-- desc:phone
  863. * @param name:cancel_timestamp type:string default:-- desc:支付倒计时(单位秒)【已支付忽略】
  864. * @return name:sh_num type:int default:-- desc:已核销票数量
  865. *
  866. * @return name:title type:string default:-- desc:标题
  867. * @return name:cover type:string default:-- desc:图片
  868. * @return name:start_time type:string default:-- desc:开始时间
  869. * @return name:end_time type:string default:-- desc:结束时间
  870. * @return name:province type:string default:-- desc:省
  871. * @return name:city type:string default:-- desc:市
  872. * @return name:county type:string default:-- desc:县区
  873. * @return name:address type:string default:-- desc:地址
  874. * @return name:pay_offline type:int default:-- desc:线下支付是否开启【0关闭1开启】
  875. * @return name:offline_user type:string default:-- desc:线下支付户名
  876. * @return name:offline_bank type:string default:-- desc:线下支付开户行
  877. * @return name:offline_card type:string default:-- desc:线下支付账号
  878. *
  879. * @return name:item_list type:array default:-- desc:票详情
  880. * @return name:item_list.id type:array default:-- desc:票详情id
  881. * @return name:item_list.ladder_title type:string default:-- desc:票标题
  882. * @return name:item_list.name type:string default:-- desc:名称
  883. * @return name:item_list.phone type:string default:-- desc:phone
  884. * @return name:item_list.phone_pre type:string default:-- desc:phone前缀
  885. * @return name:item_list.email type:string default:-- desc:email
  886. * @return name:item_list.sh_status type:int default:-- desc:是否需要审核【0待审核,1审核通过,2审核拒绝】
  887. * @return name:item_list.extend type:array default:-- desc:报名模板信息
  888. * @return name:sponsor type:array default:-- desc:主办方信息
  889. * @return name:sponsor.id type:int default:-- desc:主办方记录id
  890. * @return name:sponsor.qr_code type:string default:-- desc:二维码
  891. * @return name:sponsor.cover type:string default:-- desc:主办方logo
  892. * @return name:sponsor.official_web type:string default:-- desc:主办方官网
  893. * @return name:sponsor.title type:string default:-- desc:主办方名称
  894. * @return name:sponsor.address type:string default:-- desc:地址
  895. * @return name:sponsor.email type:string default:-- desc:email
  896. * @return name:sponsor.phone type:string default:-- desc:phone
  897. *
  898. * @return name:bill_info type:array default:-- desc:发票申请信息
  899. * @return name:bill_info.header type:string default:0 desc:抬头
  900. * @return name:bill_info.type type:int default:0 desc:发票类型
  901. * @return name:bill_info.email type:string default:0 desc:邮箱
  902. * @return name:bill_info.phone type:string default:0 desc:电话
  903. * @return name:bill_info.bank type:string default:0 desc:开户行
  904. * @return name:bill_info.card_no type:string default:0 desc:银行账号
  905. * @return name:bill_info.identify_number type:string default:0 desc:纳税人识别号
  906. * @return name:bill_info.bill_img type:string default:0 desc:点子发票url
  907. * @return name:bill_info.send_type type:string default:1 desc:1点子发票2纸质发票
  908. * @return name:bill_info.remark type:string default:0 desc:备注
  909. * @return name:express_state type:int default:0 desc:物流状态0未发货1已发货【send_type=1时忽略】
  910. * @return name:express_company_title type:int default:0 desc:物流公司【send_type=1时忽略】
  911. * @return name:express_send_no type:int default:0 desc:物流编号【send_type=1时忽略】
  912. * @return name:express_send_at type:int default:0 desc:发货时间【send_type=1时忽略】
  913. * @return name:address_info type:array default:0 desc:售货地址详情【send_type=1时忽略】
  914. * @return name:address_info.pro_name type:string default:-- desc:省名
  915. * @return name:address_info.city_name type:string default:-- desc:市名
  916. * @return name:address_info.county_name type:string default:-- desc:县区名
  917. * @return name:address_info.detail type:string default:-- desc:详细地址
  918. * @return name:address_info.phone type:string default:-- desc:联系电话
  919. * @return name:address_info.name type:string default:-- desc:联系人
  920. */
  921. public function getApplyInfo()
  922. {
  923. $detail = ActivityApply::where(['y.user_id'=>$this->user_id,'y.id'=>input('get.id')])
  924. ->alias('y')
  925. ->field('y.*,a.title,a.cover,a.start_time,a.end_time,a.province,y.pay_at,a.city,a.county,a.address,a.sponsor_id,a.pay_offline,a.offline_user,a.offline_bank,a.offline_card')
  926. ->leftJoin('Activity a','y.act_id = a.id')
  927. ->with(['itemList'])
  928. ->find()->toArray();
  929. $detail['cancel_timestamp'] = $detail['pay_state'] == 0 && $detail['cancel_state'] == 0 && strtotime($detail['create_at']) + 300 - time() > 0 ? strtotime($detail['create_at']) + 300 - time() : 0;
  930. array_walk($detail['item_list'],function (&$v){
  931. $v['extend'] = $v['extend'] ? json_decode($v['extend'],true) : null;
  932. });
  933. $detail['sh_num'] = ActivityApplyItem::where('apply_id',$detail['id'])->where('is_hx',1)->count();
  934. $detail['sponsor'] = $detail['sponsor_id'] ? ActivitySponsor::where('id',$detail['sponsor_id'])->find()->toArray() : null;
  935. $bill_info = BillApply::where(['order_type'=>3,'order_id'=>$detail['id']])->find();
  936. if($bill_info) {
  937. $bill_info = $bill_info->toArray();
  938. if($bill_info['address_info']) $bill_info['address_info'] = json_decode($bill_info['address_info'],true);
  939. }
  940. $detail['bill_info'] = !empty($bill_info) ? $bill_info : null;
  941. $this->success('ok',['detail'=>$detail]);
  942. }
  943. /**
  944. * @title 取消订单
  945. * @desc 取消订单
  946. * @author qc
  947. * @method POST
  948. * @url /api/Activity/cancelApplyOrder
  949. * @header name:Authorization require:1 desc:Token
  950. * @param name:id type:int default:-- desc:活动订单id
  951. */
  952. public function cancelApplyOrder()
  953. {
  954. $detail = ActivityApply::with(['itemList'])
  955. ->where([['user_id','=',$this->user_id],['pay_state','=',0],['cancel_state','=',0],['id','=',input('post.id')]])
  956. ->find();
  957. if(empty($detail)) $this->error('订单异常');
  958. $detail= $detail->toArray();
  959. // if($detail['pay_state'] == 1 && $detail['money'] > 0) $this->error('订单已支付');
  960. Db::startTrans();
  961. try {
  962. ActivityApply::where('id',$detail['id'])->update(['cancel_state'=>1,'status'=>2]);
  963. foreach ($detail['item_list'] as $it) {
  964. ActivityPrice::where('id',$it['price_id'])->setInc('stock',$it['num']);
  965. }
  966. Db::commit();
  967. }catch (\Exception $e) {
  968. Db::rollback();
  969. $this->error($e->getMessage());
  970. }
  971. $this->success('取消成功');
  972. }
  973. /**
  974. * @title 获取角标数量【未读数量统计】
  975. * @desc 未读数量统计
  976. * @author qc
  977. * @method GET
  978. * @url /api/Activity/getMarkNum
  979. * @header name:Authorization require:1 desc:Token
  980. * @return name:order_num type:int default:-- desc:订单数量
  981. * @return name:apply_num type:int default:-- desc:报名数量
  982. * @return name:message_num type:int default:-- desc:消息数量
  983. */
  984. public function getMarkNum()
  985. {
  986. $order_num = 0;
  987. $apply_num = 0;
  988. $message_num = UserMessage::where(['m.user_id'=>$this->user_id,'m.is_deleted'=>0,'is_read'=>0])->where('m.module','in','activity,apply,activityapply')->alias('m')->count();
  989. $total_num = $message_num;
  990. $this->success('ok',compact(['order_num','apply_num','message_num','total_num']));
  991. }
  992. /**
  993. * @title 我的发布列表
  994. * @desc 我的发布列表
  995. * @author qc
  996. * @method GET
  997. * @url /api/Activity/getMyActivityList
  998. * @header name:Authorization require:1 desc:Token
  999. * @param name:title type:string default:-- desc:搜索关键字
  1000. * @param name:page type:int default:0 desc:页数
  1001. * @param name:page_num type:int default:20 desc:每页数
  1002. * @return name:title type:string default:-- desc:标题
  1003. * @return name:cover type:string default:-- desc:海报
  1004. * @return name:release_time type:string default:-- desc:发布时间
  1005. * @return name:start_time type:string default:-- desc:开始时间
  1006. * @return name:end_time type:string default:-- desc:结束时间
  1007. * @return name:province type:string default:-- desc:省
  1008. * @return name:city type:string default:-- desc:市
  1009. * @return name:county type:string default:-- desc:县区
  1010. * @return name:address type:string default:-- desc:地址
  1011. * @return name:status type:int default:-- desc:活动状态【0已下架,1正常】
  1012. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1013. */
  1014. public function getMyActivityList(){
  1015. $title = input('get.title');
  1016. $list = \app\common\model\Activity::where(['is_deleted'=>0,'user_id'=>$this->user_id])
  1017. ->field('id,title,cover,start_time,end_time,province,city,county,address,status,release_time')
  1018. ->when($title,function ($query)use($title){
  1019. if($title) $query->where('title|label','like','%'.$title.'%');
  1020. })->order( ['id'=>'desc'])->limit($this->off_set,$this->page_num)->select()->toArray();
  1021. foreach ($list as &$v) {
  1022. $v['is_normal'] = CheckPower::checkModulesPower($v['id'],0,$this->request->controller());
  1023. }
  1024. $total_num = \app\common\model\Activity::where(['is_deleted'=>0,'user_id'=>$this->user_id])->when($title,function ($query)use($title){
  1025. if($title) $query->where('title|label','like','%'.$title.'%');
  1026. })->count();
  1027. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1028. }
  1029. /**
  1030. * @title 我的收藏【活动】
  1031. * @desc 我的收藏
  1032. * @author qc
  1033. * @method GET
  1034. * @url /api/Activity/getCollectActivity
  1035. * @header name:Authorization require:1 desc:Token
  1036. * @param name:title type:string default:-- desc:标题
  1037. * @param name:page type:int default:0 desc:页数
  1038. * @param name:page_num type:int default:20 desc:每页数
  1039. * @return name:activity_id type:string default:-- desc:活动id
  1040. * @return name:title type:string default:-- desc:标题
  1041. * @return name:cover type:string default:-- desc:海报
  1042. * @return name:release_time type:string default:-- desc:发布时间
  1043. * @return name:start_time type:string default:-- desc:开始时间
  1044. * @return name:end_time type:string default:-- desc:结束时间
  1045. * @return name:province type:string default:-- desc:省
  1046. * @return name:city type:string default:-- desc:市
  1047. * @return name:county type:string default:-- desc:县区
  1048. * @return name:address type:string default:-- desc:地址
  1049. * @return name:status type:int default:-- desc:活动状态【0已下架,1正常】
  1050. */
  1051. public function getCollectActivity()
  1052. {
  1053. $sel_where = [];
  1054. $title = input('get.title');
  1055. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  1056. $sel_where[] = ['t.user_id','=',$this->user_id];
  1057. $sel_where[] = ['t.coll_type','=',7];
  1058. $list = UserCollect::where($sel_where)
  1059. ->alias('t')
  1060. ->field('t.id,t.create_at,t.coll_id activity_id,i.title,i.cover,i.start_time,i.end_time,i.address,i.province,i.city,i.county,i.status,i.release_time')
  1061. ->leftJoin('Activity i','t.coll_id = i.id')
  1062. ->order('id desc')
  1063. ->limit($this->off_set,$this->page_num)
  1064. ->select()->toArray();
  1065. foreach ($list as &$v) {
  1066. $v['is_normal'] = CheckPower::checkModulesPower($v['activity_id'],0,$this->request->controller());
  1067. }
  1068. $total_num = UserCollect::where($sel_where)->alias('t')->leftJoin('Activity i','t.coll_id = i.id')->count();
  1069. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1070. }
  1071. /**
  1072. * @title 浏览记录【活动】
  1073. * @desc 浏览记录
  1074. * @author qc
  1075. * @method GET
  1076. * @url /api/Activity/getActivityTrack
  1077. * @header name:Authorization require:1 desc:Token
  1078. * @param name:title type:string default:-- desc:标题
  1079. * @param name:page type:int default:0 desc:页数
  1080. * @param name:page_num type:int default:20 desc:每页数
  1081. * @return name:title type:string default:-- desc:标题
  1082. * @return name:activity_id type:string default:-- desc:活动id
  1083. * @return name:title type:string default:-- desc:标题
  1084. * @return name:cover type:string default:-- desc:海报
  1085. * @return name:release_time type:string default:-- desc:发布时间
  1086. * @return name:start_time type:string default:-- desc:开始时间
  1087. * @return name:end_time type:string default:-- desc:结束时间
  1088. * @return name:province type:string default:-- desc:省
  1089. * @return name:city type:string default:-- desc:市
  1090. * @return name:county type:string default:-- desc:县区
  1091. * @return name:address type:string default:-- desc:地址
  1092. * @return name:time type:string default:-- desc:浏览时间
  1093. * @return name:status type:int default:-- desc:活动状态【0已下架,1正常】
  1094. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1095. */
  1096. public function getActivityTrack()
  1097. {
  1098. $sel_where = [];
  1099. $sel_where[] = ['t.user_id','=',$this->user_id];
  1100. $sel_where[] = ['t.type','=',7];
  1101. $title = input('get.title');
  1102. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  1103. $list = UserTrack::where($sel_where)
  1104. ->alias('t')
  1105. ->field('t.id,t.update_int,t.first_id activity_id,i.title,i.cover,i.start_time,i.end_time,i.address,i.province,i.city,i.county,i.status,i.release_time')
  1106. ->leftJoin('Activity i','t.first_id = i.id')
  1107. ->order('update_int desc')
  1108. ->limit($this->off_set,$this->page_num)
  1109. ->select()->toArray();
  1110. foreach ($list as &$v) {
  1111. $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
  1112. $v['is_normal'] = CheckPower::checkModulesPower($v['activity_id'],0,$this->request->controller());
  1113. }
  1114. $total_num = UserTrack::where($sel_where)->alias('t') ->leftJoin('Activity i','t.first_id = i.id')->count();
  1115. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1116. }
  1117. /**
  1118. * @title 我的点赞【活动】
  1119. * @desc 我的点赞
  1120. * @author qc
  1121. * @method GET
  1122. * @url /api/Activity/getTagsActivity
  1123. * @header name:Authorization require:1 desc:Token
  1124. * @param name:title type:string default:-- desc:标题
  1125. * @param name:page type:int default:0 desc:页数
  1126. * @param name:page_num type:int default:20 desc:每页数
  1127. * @return name:title type:string default:-- desc:标题
  1128. * @return name:activity_id type:string default:-- desc:活动id
  1129. * @return name:cover type:string default:-- desc:图片多张|隔开
  1130. * @return name:cover_arr type:array default:-- desc:图片多张[数组]
  1131. * @return name:content type:string default:-- desc:详情
  1132. * @return name:start_time type:string default:-- desc:开始时间
  1133. * @return name:end_time type:string default:-- desc:结束时间
  1134. * @return name:address type:string default:-- desc:地址
  1135. * @return name:price type:float default:-- desc:价格
  1136. * @return name:label type:string default:-- desc:标签[多个','隔开]
  1137. * @return name:label_name type:array default:-- desc:标签[数组]
  1138. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1139. */
  1140. public function getTagsActivity()
  1141. {
  1142. $sel_where = [];
  1143. $title = input('get.title');
  1144. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  1145. $sel_where[] = ['t.user_id','=',$this->user_id];
  1146. $sel_where[] = ['t.type','=',4];
  1147. $list = PlatformLike::where($sel_where)
  1148. ->alias('t')
  1149. ->field('t.id,t.create_at,t.like_id activity_id,i.title,i.cover,i.label,i.content,i.start_time,i.end_time,i.address,i.price')
  1150. ->leftJoin('Activity i','t.like_id = i.id')
  1151. ->order('id desc')
  1152. ->limit($this->off_set,$this->page_num)
  1153. ->select()->toArray();
  1154. foreach ($list as &$v) {
  1155. $v['cover_arr'] = $v['cover'] ? explode('|',$v['cover']) : null;
  1156. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  1157. $v['is_normal'] = CheckPower::checkModulesPower($v['activity_id'],0,$this->request->controller());
  1158. }
  1159. $total_num = PlatformLike::where($sel_where)->alias('t')->leftJoin('Activity i','t.like_id = i.id')->count();
  1160. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1161. }
  1162. /**
  1163. * @title 我的报名【门票列表】
  1164. * @desc 我的报名
  1165. * @author qc
  1166. * @method GET
  1167. * @url /api/Activity/getApplyList
  1168. * @header name:Authorization require:1 desc:Token
  1169. * @param name:sel_type type:int default:-- desc:查询类型(1报名成功2审核中,3报名失败)
  1170. * @param name:title type:string default:-- desc:标题
  1171. * @param name:page type:int default:0 desc:页数
  1172. * @param name:page_num type:int default:20 desc:每页数
  1173. * @return name:title type:string default:-- desc:标题
  1174. * @return name:activity_id type:string default:-- desc:活动id
  1175. * @return name:status type:int default:-- desc:活动状态1正常2取消
  1176. * @return name:cover type:string default:-- desc:图片
  1177. * @return name:start_time type:string default:-- desc:开始时间
  1178. * @return name:end_time type:string default:-- desc:结束时间
  1179. * @return name:sh_status type:int default:-- desc:审核【0待审核,1审核通过,2审核拒绝】
  1180. * @return name:is_hx type:int default:-- desc:是否核销(签到)【0未核销,1已核销】
  1181. * @return name:qr_code type:string default:-- desc:核销二维码
  1182. * @return name:qr_content type:string default:-- desc:核销码
  1183. * @return name:activity_title type:string default:-- desc:活动标题
  1184. * @return name:sponsor_title type:string default:-- desc:举办方
  1185. * @return name:start_time type:string default:-- desc:开始时间
  1186. * @return name:end_time type:string default:-- desc:结束时间
  1187. * @return name:province type:string default:-- desc:省
  1188. * @return name:city type:string default:-- desc:市
  1189. * @return name:county type:string default:-- desc:县区
  1190. * @return name:address type:string default:-- desc:地址
  1191. * @return name:video_id type:int default:-- desc:视频系列id
  1192. * @return name:video_item type:int default:-- desc:关联视频详情id【video_arr.id】
  1193. * @return name:video_jump type:int default:-- desc:关联视频是否能跳转【0不能跳转,1能跳转,验证是否vip】
  1194. *
  1195. * @return name:article_id type:int default:-- desc:图文系列id
  1196. * @return name:article_item type:int default:-- desc:关联图文详情id【item_list.id】
  1197. * @return name:article_jump type:int default:-- desc:关联图文是否能跳转【0不能跳转,1能跳转,验证是否vip】
  1198. * @return name:datum_id type:int default:-- desc:资料id--ppt【系列id】
  1199. * @return name:datum_item type:int default:-- desc:资料id--ppt【系列下的其中一个】
  1200. * @return name:datum_jump type:int default:-- desc:关联资料是否能跳转【0不能跳转,1能跳转,验证是否vip】
  1201. * @return name:datum_url type:int default:-- desc:关联资料链接
  1202. * @return name:label type:string default:-- desc:标签[多个','隔开]
  1203. * @return name:label_name type:array default:-- desc:标签[数组]
  1204. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1205. */
  1206. public function getApplyList()
  1207. {
  1208. $sel_where = [];
  1209. $title = input('get.title');
  1210. $sel_type = input('get.sel_type',1);
  1211. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  1212. $sel_where[] = ['t.user_id','=',$this->user_id];
  1213. $sel_where[] = ['a.cancel_state','=',0];
  1214. $sel_where[] = ['a.pay_state','=',1];
  1215. $sel_where[] = ['t.is_deleted','=',0];
  1216. switch ($sel_type) {
  1217. case 1:
  1218. $sel_where[] = ['t.sh_status','=',1];
  1219. break;
  1220. case 2:
  1221. $sel_where[] = ['t.sh_status','=',0];
  1222. break;
  1223. case 3:
  1224. $sel_where[] = ['t.sh_status','=',2];
  1225. break;
  1226. }
  1227. $list = ActivityApplyItem::where($sel_where)
  1228. ->field('t.id,a.order_no,t.act_id activity_id,t.sh_status,a.cancel_state,t.status,t.is_hx,i.title,i.status,i.cover,i.label,i.start_time,i.end_time,i.address,i.price,i.video_id,i.video_item,i.article_id,i.article_item,i.datum_id,i.datum_item,i.province,i.city,i.county,i.address')
  1229. ->alias('t')
  1230. ->leftJoin('Activity i','t.act_id = i.id')
  1231. ->leftJoin('ActivityApply a','a.id = t.apply_id')
  1232. ->order(['t.id'=>'desc'])
  1233. ->limit($this->off_set,$this->page_num)
  1234. ->select()->toArray();
  1235. foreach ($list as &$v) {
  1236. $v['article_jump'] = ArticleItem::checkVip($v['article_item'],$this->user_id);
  1237. $v['video_jump'] = VideoUrl::checkVip($v['video_item'],$this->user_id);
  1238. $v['datum_jump'] = DatumUrl::checkVip($v['datum_item'],$this->user_id);
  1239. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  1240. $v['is_normal'] = CheckPower::checkModulesPower($v['activity_id'],0,$this->request->controller());
  1241. }
  1242. $total_num = ActivityApplyItem::where($sel_where)
  1243. ->alias('t')
  1244. ->leftJoin('Activity i','t.act_id = i.id')
  1245. ->leftJoin('ActivityApply a','a.id = t.apply_id')->count();
  1246. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1247. }
  1248. /**
  1249. * @title 获取门票详情
  1250. * @desc 获取门票详情
  1251. * @author qc
  1252. * @url /api/Activity/getTicketInfo
  1253. * @method GET
  1254. * @param name:id type:int require default:-- desc:门票id
  1255. * @return name:id type:array default:-- desc:票详情id
  1256. * @return name:ladder_title type:string default:-- desc:票标题
  1257. * @return name:status type:string default:-- desc:票状态【0未支付1已支付2已取消3退款处理中4已退款】
  1258. * @return name:phone type:string default:-- desc:phone
  1259. * @return name:phone_pre type:string default:-- desc:phone前缀
  1260. * @return name:email type:string default:-- desc:email
  1261. * @return name:sh_status type:int default:-- desc:审核【0待审核,1审核通过,2审核拒绝】
  1262. * @return name:is_hx type:int default:-- desc:是否核销(签到)【0未核销,1已核销】
  1263. * @return name:hx_time type:string default:-- desc:核销时间
  1264. * @return name:qr_code type:string default:-- desc:核销二维码
  1265. * @return name:qr_content type:string default:-- desc:核销码
  1266. * @return name:activity_title type:string default:-- desc:活动标题
  1267. * @return name:sponsor_title type:string default:-- desc:举办方
  1268. * @return name:start_time type:string default:-- desc:开始时间
  1269. * @return name:end_time type:string default:-- desc:结束时间
  1270. * @return name:province type:string default:-- desc:省
  1271. * @return name:city type:string default:-- desc:市
  1272. * @return name:county type:string default:-- desc:县区
  1273. * @return name:address type:string default:-- desc:地址
  1274. * @return name:refund_info type:array default:-- desc:退款信息【无退款信息是null】
  1275. * @return name:refund_info.status type:int default:-- desc:0待审核1同意退款2审核拒绝3通过且退款4退款异常5取消申请
  1276. */
  1277. public function getTicketInfo()
  1278. {
  1279. $item_id = input('get.id');
  1280. $info = ActivityApplyItem::where('i.id',$item_id) ->where('i.user_id',$this->user_id)
  1281. ->field('i.id,i.status,i.is_deleted,i.name,i.act_id,i.phone,sh_status,i.email,i.qr_code,i.code,i.is_hx,i.hx_time,qr_content,i.phone_pre,a.pay_state,c.title activity_title,c.start_time,c.end_time,s.title sponsor_title,c.province,c.city,c.county,c.address')
  1282. ->alias('i')
  1283. ->leftJoin('ActivityApply a','a.id = i.apply_id')
  1284. ->leftJoin('Activity c','c.id = i.act_id')
  1285. ->leftJoin('ActivitySponsor s','s.id = c.sponsor_id')
  1286. ->find()->toArray();
  1287. if($info['is_deleted'] == 1) $this->error('门票详情有误');
  1288. $info['refund_info'] = GoodsOrderRefund::getActivityRefund($item_id);
  1289. // if(!$info['pay_state']) $this->error('订单未支付');
  1290. $this->success('ok',['detail'=>$info]);
  1291. }
  1292. /**
  1293. * @title 门票核销
  1294. * @desc 门票核销
  1295. * @author qc
  1296. * @url /api/Activity/hxOrder
  1297. * @method POST
  1298. * @param name:qr_content type:int require default:-- desc:核销码内容
  1299. */
  1300. public function hxOrder(){
  1301. $qr_content = input('post.qr_content');
  1302. if(!$qr_content) $this->error('没有核销内容');
  1303. if(!$this->user_info['is_hx'])$this->error('没有核销权限');
  1304. $item_info = ActivityApplyItem::where(['i.qr_content'=>$qr_content,'is_hx'=>0])
  1305. ->alias('i')->field('i.id,i.is_hx,i.status,i.apply_id,i.is_deleted,a.status,a.cancel_state,a.pay_state,a.refund_state')
  1306. ->leftJoin("ActivityApply a",'a.id = i.apply_id')->find();
  1307. if(!$item_info) $this->error('没有找到核销记录');
  1308. if($item_info->cancel_state)$this->error('订单已取消');
  1309. $refund_info = StoreOrderRefund::getRefundInfo($item_info['apply_id'],$item_info['id'],1);
  1310. if(!empty($refund_info && in_array($refund_info['status'],[0,1,3,5])))$this->error('已申请退款');
  1311. if(!in_array($item_info->refund_state,[0,3]))$this->error('订单已申请退款');
  1312. if(!in_array($item_info->status,[1]))$this->error('票状态异常');
  1313. ActivityApplyItem::where('id',$item_info['id'])->update(['is_hx'=>1,'ticket_status'=>1,'hx_user'=>$this->user_id,'hx_time'=>date("Y-m-d H:i:s")]);
  1314. $this->success('核销成功');
  1315. }
  1316. /**
  1317. * @title 申请退款
  1318. * @desc 申请退款
  1319. * @author qc
  1320. * @url /api/Activity/applyRefund
  1321. * @method POST
  1322. * @param name:order_id type:int require default:-- desc:订单id
  1323. */
  1324. public function applyRefund()
  1325. {
  1326. $order_id = input('order_id');
  1327. $res = \app\common\service\Activity::orderRefundApply($order_id);
  1328. $res['code'] == 200 ? $this->success($res['msg']) : $this->error($res['msg']);
  1329. }
  1330. /**
  1331. * @title 取消申请退款
  1332. * @desc 取消申请退款
  1333. * @author qc
  1334. * @url /api/Activity/applyRefund
  1335. * @method POST
  1336. * @param name:order_id type:int require default:-- desc:订单id
  1337. */
  1338. public function cancelRefund()
  1339. {
  1340. $order_id = input('order_id');
  1341. $order_info = ActivityApply::where('id',$order_id)->where('user_id',$this->user_id)->find();
  1342. if(empty($order_info)) $this->error('订单不存在');
  1343. if(in_array($order_info['refund_state'],[5]))$this->error('订单已退款');
  1344. StoreOrderRefund::where(['order_id'=>$order_id,'source'=>1,'type'=>1])->update(['status'=>5]);
  1345. ActivityApply::where('id',$order_id)->update(['status'=>6]);
  1346. $this->success('取消成功');
  1347. }
  1348. /**
  1349. * @title 获取发票详情
  1350. * @desc 获取发票详情
  1351. * @author qc
  1352. * @url /api/Activity/getBillInfo
  1353. * @method GET
  1354. * @param name:id type:int require default:-- desc:订单id
  1355. * @return name:id type:array default:-- desc:票详情id
  1356. * @return name:header type:string default:0 desc:抬头
  1357. * @return name:type_title type_title:int default:0 desc:发票类型
  1358. * @return name:email type:string default:0 desc:邮箱
  1359. * @return name:create_at type:string default:0 desc:申请时间
  1360. * @return name:phone type:string default:0 desc:电话
  1361. * @return name:bank type:string default:0 desc:开户行
  1362. * @return name:status type:int default:0 desc:状态(0申请中1已开票2已完成【现场领取或是确认收货】)
  1363. * @return name:card_no type:string default:0 desc:银行账号
  1364. * @return name:identify_number type:string default:0 desc:纳税人识别号
  1365. * @return name:send_type type:string default:1 desc:1点子发票2纸质发票
  1366. * @return name:remark type:string default:0 desc:备注
  1367. * @return name:bill_img type:string default:0 desc:点子发票【图片】
  1368. * @return name:bill_time type:string default:0 desc:开票时间
  1369. * @return name:address type:string default:0 desc:公司地址
  1370. * @return name:order_pay type:string default:0 desc:订单是否已支付【0未支付1已支付】
  1371. * @return name:express_state type:int default:0 desc:物流状态0未发货1已发货【send_type=1时忽略】
  1372. * @return name:express_company_title type:int default:0 desc:物流公司【send_type=1时忽略】
  1373. * @return name:express_send_no type:int default:0 desc:物流编号【send_type=1时忽略】
  1374. * @return name:express_send_at type:int default:0 desc:发货时间【send_type=1时忽略】
  1375. * @return name:address_info type:array default:0 desc:售货地址详情【send_type=1时忽略】
  1376. * @return name:address_info.pro_name type:string default:-- desc:省名
  1377. * @return name:address_info.city_name type:string default:-- desc:市名
  1378. * @return name:address_info.county_name type:string default:-- desc:县区名
  1379. * @return name:address_info.detail type:string default:-- desc:详细地址
  1380. * @return name:address_info.phone type:string default:-- desc:联系电话
  1381. * @return name:address_info.name type:string default:-- desc:联系人
  1382. *
  1383. */
  1384. public function getBillInfo()
  1385. {
  1386. //'order_type'=>3,
  1387. $info = BillApply::where(['b.id'=>input('get.id')])
  1388. ->alias('b')->field('b.*,t.title type_title,a.money')
  1389. ->leftJoin('BillType t','t.id = b.type')
  1390. ->leftJoin('ActivityApply a','a.id = b.order_id')
  1391. ->find();
  1392. if(empty($info)) $this->error('该订单未申请发票');
  1393. $info = $info->toArray();
  1394. if($info['address_info']) $info['address_info'] = json_decode($info['address_info'],true);
  1395. $this->success('ok',['detail'=>$info]);
  1396. }
  1397. /**
  1398. * @title 获取纸质发票物流详情
  1399. * @desc 获取纸质发票物流详情
  1400. * @author qc
  1401. * @url /api/Activity/deliveryDetails
  1402. * @method GET
  1403. * @header name:Authorization require:1 desc:Token
  1404. * @param name:id type:string require:1 default:-- desc:发票申请详情记录
  1405. * @return name:number type:string default:-- desc:单号
  1406. * @return name:type type:string default:-- desc:快递类型
  1407. * @return name:list type:array default:-- desc:数据列表
  1408. * @return name:list.time type:string default:-- desc:时间
  1409. * @return name:list.status type:string default:-- desc:内容
  1410. * @return name:deliverystatus type:int default:-- desc:0:快递收件(揽件)1.在途中2.正在派件3.已签收4.派送失败5.疑难件6.退件签收
  1411. * @return name:issign type:int default:-- desc:是否签收(1.是否签收)
  1412. * @return name:expName type:string default:-- desc:快递公司名称
  1413. * @return name:expSite type:string default:-- desc:快递公司官网
  1414. * @return name:expPhone type:string default:-- desc:快递公司电话
  1415. * @return name:courier type:string default:-- desc:快递员 或 快递站(没有则为空)
  1416. * @return name:courierPhone type:string default:-- desc:快递员电话 (没有则为空)
  1417. * @return name:updateTime type:string default:-- desc:快递轨迹信息最新时间
  1418. * @return name:takeTime type:string default:-- desc:发货到收货消耗时长 (截止最新轨迹)
  1419. * @return name:logo type:string default:-- desc:快递公司LOGO
  1420. */
  1421. public function deliveryDetails(){
  1422. $this->success('ok', get_delivery());
  1423. $send_no = BillApply::where('id',input('get.id'))->value('express_send_no');
  1424. if(!$send_no) $this->error('订单没有发货');
  1425. $data = get_delivery($send_no);
  1426. $this->success('ok',$data);
  1427. }
  1428. /**
  1429. * @title 订单列表【报名订单列表】
  1430. * @desc 订单列表
  1431. * @author qc
  1432. * @url /api/Activity/getApplyOrderList
  1433. * @method GET
  1434. * @header name:Authorization require:1 desc:Token
  1435. * @param name:sel_type type:int require:1 default:0 desc:0全部1线上订单2转账订单3免费订单
  1436. * @param name:sel_status type:int require:1 default:-1 desc:查询状态-1全部0待支付1已支付3退款中4已取消
  1437. * @return name:id type:string default:-- desc:订单id
  1438. * @return name:title type:string default:-- desc:活动标题
  1439. * @return name:cover type:string default:-- desc:活动海报
  1440. * @return name:start_time type:string default:-- desc:开始时间
  1441. * @return name:end_time type:string default:-- desc:结束时间
  1442. * @return name:province type:string default:-- desc:省
  1443. * @return name:city type:string default:-- desc:市
  1444. * @return name:county type:string default:-- desc:县区
  1445. * @return name:address type:string default:-- desc:地址
  1446. * @return name:money type:float default:-- desc:订单金额
  1447. * @return name:pay_type type:int default:-- desc:支付方式(1.h5微信,2.h5支付宝,3.app微信,4.app支付宝,5.h5微信内支付,9线下支付)
  1448. * @return name:pay_offline type:int default:-- desc:线下支付是否开启【0关闭1开启】
  1449. * @return name:offline_user type:string default:-- desc:线下支付户名
  1450. * @return name:offline_bank type:string default:-- desc:线下支付开户行
  1451. * @return name:offline_card type:string default:-- desc:线下支付账号
  1452. * @return name:pay_state type:int default:-- desc:是否支付【0否1是】
  1453. * @return name:sh_num type:int default:-- desc:已核销票数量
  1454. * @return name:refund_state type:int default:-- desc:退款状态【0未申请1审核中2同意3拒绝4退款异常5退款成功6取消申请】
  1455. * @return name:bill_info type:array default:-- desc:发票申请详情
  1456. * @return name:bill_info.id type:int default:-- desc:发票申请详情id
  1457. */
  1458. public function getApplyOrderList()
  1459. {
  1460. $sel_type = input('get.sel_type',0);
  1461. $sel_status = input('get.sel_status',-1);
  1462. $where = [];
  1463. $where[] = ['o.user_id','=',$this->user_id];
  1464. $where[] = ['o.is_deleted','=',0];
  1465. switch ($sel_type) {
  1466. case 1:
  1467. $where[] = ['o.money','>',0];
  1468. $where[] = ['o.pay_type','in','1,2,3,4,5,6,7'];
  1469. break;
  1470. case 2:
  1471. $where[] = ['o.money','>',0];
  1472. $where[] = ['o.pay_type','=',9];
  1473. break;
  1474. case 3:
  1475. $where[] = ['o.money','=',0];
  1476. break;
  1477. }
  1478. switch ($sel_status) {
  1479. case 0:
  1480. $where[] = ['o.pay_state','=',0];
  1481. $where[] = ['o.cancel_state','=',0];
  1482. break;
  1483. case 1:
  1484. $where[] = ['o.pay_state','=',1];
  1485. $where[] = ['o.refund_state','=',0];
  1486. break;
  1487. case 3:
  1488. $where[] = ['o.refund_state','in',[1,2,3,4,5]];
  1489. break;
  1490. case 4:
  1491. $where[] = ['o.cancel_state','=',1];
  1492. break;
  1493. }
  1494. //var_dump($where);
  1495. //testaaaa
  1496. //testbbbb
  1497. $list = ActivityApply::where($where)
  1498. ->field('o.id,o.money,o.order_no,o.sh_state,o.total_money,pay_type,o.pay_state,o.cancel_state,o.refund_state,o.create_at,o.act_id,a.title,a.start_time,a.end_time,a.cover,a.pay_offline,offline_user,offline_bank,offline_card,province,city,county,address')
  1499. ->alias('o')
  1500. ->order('o.id desc')
  1501. ->leftJoin('Activity a','o.act_id = a.id')
  1502. ->select()->toArray();
  1503. array_walk($list,function (&$v){
  1504. $bill_info = BillApply::where(['order_type'=>3,'order_id'=>$v['id']])->find();
  1505. if($bill_info) {
  1506. $bill_info = $bill_info->toArray();
  1507. if($bill_info['address_info']) $bill_info['address_info'] = json_decode($bill_info['address_info'],true);
  1508. }
  1509. $v['bill_info'] = $bill_info;
  1510. $v['sh_num'] = ActivityApplyItem::where('apply_id',$v['id'])->where('is_hx',1)->count();
  1511. });
  1512. $total_num = ActivityApply::where($where) ->alias('o') ->leftJoin('Activity a','o.act_id = a.id')->count();
  1513. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1514. }
  1515. /**
  1516. * @title 删除订单
  1517. * @desc 删除订单
  1518. * @author qc
  1519. * @url /api/Activity/delApplyOrder
  1520. * @method POST
  1521. * @param name:order_id type:int require default:-- desc:订单id
  1522. */
  1523. public function delApplyOrder()
  1524. {
  1525. $order_id = input('order_id');
  1526. ActivityApply::where('id',$order_id)->where('user_id',$this->user_id)->update(['is_deleted'=>1]);
  1527. $this->success('删除成功');
  1528. }
  1529. /**
  1530. * @title 删除门票
  1531. * @desc 删除门票
  1532. * @author qc
  1533. * @url /api/Activity/delTicket
  1534. * @method POST
  1535. * @param name:id type:int require default:-- desc:门票id
  1536. */
  1537. public function delTicket()
  1538. {
  1539. ActivityApplyItem::where('id',input('post.id'))->where('user_id',$this->user_id)->update(['is_deleted'=>1]);
  1540. $this->success('删除成功');
  1541. }
  1542. /**
  1543. * @title 活动消息
  1544. * @desc 活动消息
  1545. * @author qc
  1546. * @url /api/Activity/getMessageList
  1547. * @method GET
  1548. * @param name:page type:int default:0 desc:页数
  1549. * @param name:page_num type:int default:20 desc:每页数
  1550. * @param name:id type:int default:-- desc:消息记录id
  1551. * @return name:content type:string default:-- desc:内容
  1552. * @return name:create_at type:string default:-- desc:时间
  1553. * @return name:relation_id type:int default:-- desc:活动id
  1554. * @return name:type_id type:int default:-- desc:类型标识:1活动报名,2活动变更,3活动提醒,4活动订单
  1555. * @return name:children_id type:int default:-- desc:相关详情id【type_id等于1或3是票的id,type_id等于2是活动id,type_id=4是订单id,type_id=5是申请发票记录id】
  1556. * @return name:is_read type:int default:-- desc:是否已读【0否1是】
  1557. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1558. */
  1559. public function getMessageList()
  1560. {
  1561. $list = UserMessage::where(['m.user_id'=>$this->user_id,'m.is_deleted'=>0])->where('m.module','in','activity,apply,activityapply')->alias('m')
  1562. ->limit($this->off_set,$this->page_num)->order(['m.id'=>'desc'])
  1563. ->select()->toArray();
  1564. array_walk($list,function (&$v){
  1565. $massage = UserMessage::where(['user_id'=>$this->user_id,'is_deleted'=>0])
  1566. ->where('id',$v['id'])
  1567. ->where('title','like','%发票%')->find();
  1568. if($massage){
  1569. $v['is_normal'] = CheckPower::checkModulesPower($v['relation_id'],0,'activityapply');
  1570. }else{
  1571. $v['is_normal'] = CheckPower::checkModulesPower($v['relation_id'],0,$v['module']);
  1572. }
  1573. });
  1574. $total_num = UserMessage::where(['m.user_id'=>$this->user_id,'m.is_deleted'=>0])->where('m.module','in','activity,apply,activityapply')->alias('m')->count();
  1575. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1576. }
  1577. /**
  1578. * @title 消息已读&&未读变更
  1579. * @desc 支持批量选择
  1580. * @author qc
  1581. * @method POST
  1582. * @url /api/Activity/unreadChange
  1583. * @header name:Authorization require:1 desc:Token
  1584. * @param name:id type:string default:-- desc:记录id(多个逗号隔开,不传修改全部])
  1585. * @param name:is_read type:int default:1 desc:变更类型【0消息变更为未读,1变更为已读】
  1586. */
  1587. public function unreadChange()
  1588. {
  1589. $id = input('post.id');
  1590. $where[] = ['user_id','=',$this->user_id];
  1591. $where[] = ['module','in','activity,apply,activityapply'];
  1592. if($id) $where[] = ['id','in',$id];
  1593. $message = UserMessage::where($where)->select();
  1594. UserMessage::where($where)->update(['is_read'=>input('post.is_read')]);
  1595. $this->success('消息变更成功');
  1596. }
  1597. /**
  1598. * @title 批量删除||批量取消
  1599. * @desc 删除||取消
  1600. * @author qc
  1601. * @method POST
  1602. * @url /api/Activity/batchesDel
  1603. * @header name:Authorization require:1 desc:Token
  1604. * @param name:id type:string default:1 desc:记录id【多个用逗号隔开=>'1,2'】
  1605. * @param name:type type:string default:1 desc:消息类型【1消息记录删除】
  1606. */
  1607. public function batchesDel()
  1608. {
  1609. $type = input('post.type',1);
  1610. $del_where = [];
  1611. $del_where[] = ['id','in',input('post.id')];
  1612. if(in_array($type,[1])) UserMessage::where($del_where)->update(['is_deleted'=>1,'is_read'=>1]);
  1613. $this->success('操作成功');
  1614. }
  1615. /**
  1616. * @title 申请开票
  1617. * @desc 申请开票
  1618. * @author qc
  1619. * @method POST
  1620. * @url /api/Activity/applyBill
  1621. * @header name:Authorization require:1 desc:Token
  1622. * @param name:id type:string default:1 desc:订单id
  1623. * @param name:bill_info type:string default:-- desc:发票信息
  1624. * @param name:bill_info.type type:int default:-- desc:类型id
  1625. * @param name:bill_info.header type:string default:-- desc:抬头名称[公司名称||个人名称]
  1626. * @param name:bill_info.identify_number type:string default:-- desc:纳税人识别号
  1627. * @param name:bill_info.email type:string default:-- desc:邮箱
  1628. * @param name:bill_info.remark type:string default:-- desc:备注
  1629. *
  1630. * @param name:address_info type:string default:-- desc:收货信息--json【非物流不传】
  1631. * @param name:address_info.type type:int require:1 default:-- desc:领取方式【1现场2快递】
  1632. * @param name:address_info.send_type type:int require:1 default:-- desc:申请类型【1点子发票2纸质发票】
  1633. * @param name:address_info.pro_name type:string require:1 default:-- desc:省名【快递必传】
  1634. * @param name:address_info.city_name type:string require:1 default:-- desc:市名【快递必传】
  1635. * @param name:address_info.county_name type:string require:1 default:-- desc:县区名【快递必传】
  1636. * @param name:address_info.detail type:string require:0 default:-- desc:详细地址【快递必传】
  1637. * @param name:address_info.phone type:string require:1 default:-- desc:联系电话【快递必传】
  1638. * @param name:address_info.name type:string require:1 default:-- desc:联系人【快递必传】
  1639. */
  1640. public function applyBill()
  1641. {
  1642. $order_id = input('post.id');
  1643. $post_bill = input('post.bill_info');
  1644. $post_address = input('post.address_info');
  1645. $bill_info = json_decode(stripslashes($post_bill),true);
  1646. $address_info = json_decode(stripslashes($post_address),true);
  1647. $order_info = ActivityApply::where('id',$order_id)->where('user_id',$this->user_id)->find()->toArray();
  1648. if($order_info['money'] <= 0 ) $this->error('免费订单无法申请开票');
  1649. if(!$order_info['pay_state'])$this->error('订单未支付');
  1650. if(in_array($order_info['refund_state'],[1,2,4,5]))$this->error('订单已申请退款');
  1651. $refund_money = StoreOrderRefund::getRefundMoney($order_id);
  1652. if($refund_money >= $order_info['money'])$this->error('订单已全额退款');
  1653. if(BillApply::checkBillApply($order_id,3)) $this->error('已申请开票');
  1654. $user_info = $this->userInfo();
  1655. // 是否是选择的已有的抬头
  1656. /* if(isset($bill_info['header_id']) && $bill_info['header_id']) {
  1657. $bill_info = BillHeader::where('id',$bill_info['header_id'])->find()->toArray();
  1658. }else{
  1659. $bill_info = BillHeader::saveHeader(array_merge($bill_info,['user_id'=>$user_info['id'],'is_deleted'=>1]));
  1660. }*/
  1661. // 是否有物流地址
  1662. if(!empty($address_info) && isset($address_info['type']) && $address_info['type'] == 2)$address_info = DeliveryAddress::saveAddress(array_merge($address_info,['user_id'=>$user_info['id'],'is_deleted'=>1]));
  1663. $ret_val = UserSynth::buildBillApply($user_info['id'], $order_info['id'], 3,$bill_info,!empty($address_info)&& isset($address_info['type']) && $address_info['type'] == 2 ? $address_info['id']:0,1,$bill_info['remark'],0);
  1664. if($ret_val['code'] != 200) $this->error($ret_val['msg']);
  1665. $this->success('申请成功');
  1666. }
  1667. }