DivFromController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <?php
  2. /****************************************************************
  3. * Author: libaojia
  4. * Date: 2017/8/25 下午1:51
  5. * Email: livsyitian@163.com
  6. * QQ: 995265288
  7. * User: 芸众商城 www.yunzshop.com
  8. ****************************************************************/
  9. namespace app\frontend\modules\from\controllers;
  10. use app\common\components\ApiController;
  11. use app\common\models\Goods;
  12. use app\common\models\GoodsCategory;
  13. use app\common\models\order\OrderInvoice;
  14. use app\common\services\DivFromService;
  15. use app\common\services\IDCardService;
  16. use app\framework\Http\Request;
  17. use app\frontend\models\Member;
  18. use app\common\models\MemberCertified;
  19. use Yunshop\Invoice\models\InvoiceCategory;
  20. use Yunshop\Invoice\models\InvoiceGoods;
  21. use Yunshop\Invoice\models\InvoiceRelation;
  22. use Yunshop\Invoice\models\InvoiceRise;
  23. class DivFromController extends ApiController
  24. {
  25. /**
  26. * 商品表单是否显示
  27. * @return \Illuminate\Http\JsonResponse
  28. */
  29. public function isDisplay(Request $request, $integrated = null)
  30. {
  31. $goods_ids = json_decode(request()->input('goods_ids'),true);
  32. if (!is_array($goods_ids)) {
  33. if(is_null($integrated)){
  34. return $this->errorJson('未获取到商品ID集');
  35. }else{
  36. return show_json(0,'未获取到商品ID');
  37. }
  38. }
  39. $status = DivFromService::isDisplay($goods_ids,\YunShop::app()->getMemberId());
  40. if(is_null($integrated)){
  41. return $this->successJson('ok',['status'=> $status,'member_status'=>DivFromService::getMemberStatus(\YunShop::app()->getMemberId())]);
  42. }else{
  43. return show_json(1,['status'=> $status,'member_status'=>DivFromService::getMemberStatus(\YunShop::app()->getMemberId())]);
  44. }
  45. }
  46. /**
  47. * 商品表单规则说明
  48. * @return \Illuminate\Http\JsonResponse
  49. */
  50. public function explain(Request $request, $integrated = null)
  51. {
  52. $explain = array_pluck(\Setting::getAllByGroup('div_from')->toArray(), 'value', 'key');
  53. if (is_null($integrated)){
  54. return $this->successJson('ok',$explain );
  55. }else{
  56. return show_json(1,$explain);
  57. }
  58. }
  59. /**
  60. * 商品表单规则说明
  61. * @return \Illuminate\Http\JsonResponse
  62. */
  63. public function deliveryTime(Request $request, $integrated = null)
  64. {
  65. $delivery_time = \Setting::get('shop.trade.delivery_time') ? 1 : 0;
  66. $deliveryTime = [
  67. 'status' => $delivery_time,
  68. 'time' => [
  69. '8:00 - 10:00',
  70. '10:00 - 12:00',
  71. '14:00 - 16:00',
  72. '16:00 - 18:00',
  73. ]
  74. ];
  75. if (is_null($integrated)){
  76. return $this->successJson('ok',$deliveryTime );
  77. }else{
  78. return show_json(1,$deliveryTime);
  79. }
  80. }
  81. //判断是否开启发票
  82. public function isinvoice(Request $request, $integrated = null)
  83. {
  84. $mid = \YunShop::app()->getMemberId();
  85. $setting = \Setting::get('plugin.invoice');//新发票设置
  86. //发票类型
  87. $type = [
  88. 0 => '电子发票',
  89. 1 => '纸质发票',
  90. 2 => '专用发票',
  91. ];
  92. //发票内容
  93. $content_type = [
  94. 0 => '商品明细',
  95. 1 => '商品类型',
  96. ];
  97. $invoice_type = $content = $rises = [];
  98. $tax_rate = 0;
  99. if (app('plugins')->isEnabled('invoice') && $setting['is_open']) {
  100. $is_notice = $is_content = 1;
  101. $rise = InvoiceRise::uniacid()
  102. ->where('member_id', $mid)
  103. ->get();
  104. $rise = $rise->isEmpty() ? [] : $rise->toArray();
  105. foreach ($rise as $value) {
  106. $default_rise = [
  107. 'collect_name' => $value['collect_name'],
  108. 'gmf_taxpayer' => $value['tax_num'],
  109. 'gmf_bank_admin' => $value['bank_admin'],
  110. 'gmf_address' => $value['address'],
  111. 'gmf_bank' => $value['bank'],
  112. 'gmf_mobile' => $value['mobile'],
  113. 'col_address' => $value['address'],
  114. 'email' => $value['email']
  115. ];
  116. if ($value['type'] == '0') {
  117. $rises['personal'][] = $value;
  118. $value['is_default'] == 1 && $personal_default_rise = $default_rise;
  119. }
  120. if ($value['type'] == '1') {
  121. $rises['company'][] = $value;
  122. $value['is_default'] == 1 && $unit_default_rise = $default_rise;
  123. }
  124. }
  125. $tax_rate = $this->goTaxRate() ?: 0;
  126. foreach ($setting['content'] as $value) {
  127. $content[] = [
  128. 'name' => $content_type[$value],
  129. 'value' => $value
  130. ];
  131. }
  132. foreach ($content as $key => $item) {
  133. if (!$item['name']) {
  134. unset($content[$key]);
  135. }
  136. }
  137. foreach ($setting['invoice_type'] as $value) {
  138. $invoice_type[] = [
  139. 'name' => $type[$value],
  140. 'value' => $value
  141. ];
  142. }
  143. foreach ($invoice_type as $key => $item) {
  144. if (!$item['name']) {
  145. unset($invoice_type[$key]);
  146. }
  147. }
  148. } else {
  149. $is_notice = $is_content = 0;
  150. //旧发票(商城设置)
  151. $trade = \Setting::get('shop.trade');
  152. $trade_invoice_set = [
  153. //电子
  154. 0 => [
  155. 'type_name' => $type[0],
  156. 'is_open' => $trade['invoice']['electron'] ?? 0
  157. ],
  158. //纸质
  159. 1 => [
  160. 'type_name' => $type[1],
  161. 'is_open' => $trade['invoice']['papery'] ?? 0
  162. ],
  163. ];
  164. foreach ($trade_invoice_set as $key => $value) {
  165. if ($value['is_open']) {
  166. $invoice_type[] = [
  167. 'name' => $value['type_name'],
  168. 'value' => $key
  169. ];
  170. }
  171. }
  172. foreach ($invoice_type as $key => $item) {
  173. if (!$item['name']) {
  174. unset($invoice_type[$key]);
  175. }
  176. }
  177. }
  178. // $sql_select = ['id', 'collect_name', 'email', 'gmf_taxpayer as tax_num', 'gmf_bank_admin as bank_admin', 'gmf_address as address', 'gmf_bank as bank', 'gmf_mobile as mobile', 'col_address', 'col_name', 'col_mobile', 'content'];
  179. $sql_select = ['id', 'collect_name', 'email', 'gmf_taxpayer', 'gmf_bank_admin', 'gmf_address', 'gmf_bank', 'gmf_mobile', 'col_address', 'col_name', 'col_mobile', 'content'];
  180. $sqlData = [
  181. 'personal' => [
  182. 'where' => ['rise_type' => 1],
  183. ],
  184. 'unit' => [
  185. 'where' => ['rise_type' => 0],
  186. ],
  187. 'special' => [
  188. 'where' => ['invoice_type' => 2],
  189. ],
  190. ];
  191. //最近订单发票
  192. $default_rise = [];
  193. foreach ($sqlData as $key => $value) {
  194. if (in_array($key,['personal','unit'])) {
  195. $default_rise[$key] = OrderInvoice::uniacid()->select($sql_select)->where($value['where'])->where('invoice_type','!=',2)->where('uid',$mid)->orderBy('created_at','desc')->first();
  196. } else {
  197. $default_rise[$key] = OrderInvoice::uniacid()->select($sql_select)->where($value['where'])->where('uid',$mid)->orderBy('created_at','desc')->first();
  198. }
  199. }
  200. // //收票人信息
  201. // $default_rise['taker_info'] = [
  202. // //电子
  203. // 'electronic' => OrderInvoice::uniacid()->select('col_mobile', 'email')->where('invoice_type', 0)->orderBy('created_at','desc')->first(),
  204. // //纸质
  205. // 'paper' => OrderInvoice::uniacid()->select('col_name', 'col_mobile', 'col_address')->where('invoice_type', 1)->orderBy('created_at', 'desc')->first(),
  206. // //专用
  207. // 'special' => OrderInvoice::uniacid()->select('col_name', 'col_mobile', 'col_address')->where('invoice_type', 2)->orderBy('created_at','desc')->first(),
  208. // ];
  209. !empty($personal_default_rise) && $default_rise['personal'] = $personal_default_rise;
  210. !empty($unit_default_rise) && $default_rise['unit'] = $unit_default_rise;
  211. $result = [
  212. // 'is_open' => empty($setting['is_open']) ? 0 : $setting['is_open'],
  213. 'is_open' => !empty($invoice_type) ? 1 : 0,
  214. 'invoice_type' => $invoice_type,
  215. 'content' => $content,
  216. 'is_notice' => $is_notice,//1-显示发票须知,0-不显示
  217. 'is_content' => $is_content,//1-显示发票内容,0-不显示
  218. 'notice' => empty($setting['notice']) ? '' : $setting['notice'],
  219. 'rises' => $rises,
  220. 'tax_rate' => $tax_rate,
  221. 'default_rise' => $default_rise,
  222. // 'default_rise' => array_filter($default_rise),
  223. ];
  224. return show_json(1, $result);
  225. }
  226. /**
  227. * 修改会员真实姓名、身份证ID
  228. * @return \Illuminate\Http\JsonResponse
  229. */
  230. public function updateMemberInfo()
  231. {
  232. $member_name = \YunShop::request()->member_name;
  233. if (!$member_name) {
  234. return $this->errorJson('会员真实名称不能为空');
  235. }
  236. $member_card = \YunShop::request()->member_card;
  237. if (!$member_card) {
  238. return $this->errorJson('会员身份证号码不能为空');
  239. }
  240. if (!IDCardService::isCard($member_card)) {
  241. return $this->errorJson('请输入正确的身份证号码');
  242. }
  243. if (!\YunShop::app()->getMemberId()) {
  244. return $this->errorJson('未获取到会员ID');
  245. }
  246. Member::where('uid', \YunShop::app()->getMemberId())->update(['realname' => $member_name, 'idcard' => $member_card]);
  247. MemberCertified::insertData(array(
  248. 'uniacid' => \YunShop::app()->uniacid,
  249. 'member_id' => \YunShop::app()->getMemberId(),
  250. 'realname' => $member_name,
  251. 'idcard' => $member_card,
  252. 'remark' => '表单修改实名信息',
  253. 'created_at' => time(),
  254. 'updated_at' => time()
  255. ));
  256. return $this->successJson('ok');
  257. }
  258. public function getMemberInfo(Request $request, $integrated = null)
  259. {
  260. $MemberInfo = DivFromService::getMemberCardAndName(\YunShop::app()->getMemberId());
  261. if (!$MemberInfo) {
  262. if(is_null($integrated)){
  263. return $this->errorJson('未获取到会员信息!!');
  264. }else{
  265. return show_json(1,'未获取到会员信息!!');
  266. }
  267. }
  268. if(is_null($integrated)){
  269. return $this->successJson('ok',$MemberInfo);
  270. }else{
  271. return show_json(1,$MemberInfo);
  272. }
  273. }
  274. private function getCouponSet(Request $request, $integrated = null)
  275. {
  276. $couponSet = \Setting::get('shop.coupon')['coupon_remind'] ?: '0';
  277. if(is_null($integrated)){
  278. return $this->successJson('ok',$couponSet);
  279. }else{
  280. return show_json(1,$couponSet);
  281. }
  282. }
  283. public function getParams(Request $request)
  284. {
  285. //判断是否开启发票
  286. $this->dataIntegrated($this->isinvoice($request, true), 'sinvoice');
  287. //商品表单是否显示
  288. $this->dataIntegrated($this->isDisplay($request, true), 'isDisplay');
  289. //获取会员详情
  290. $this->dataIntegrated($this->getMemberInfo($request, true), 'getMemberInfo');
  291. //商品表单规则说明
  292. $this->dataIntegrated($this->explain($request, true), 'explain');
  293. //共享链支付协议
  294. $this->dataIntegrated(\app\frontend\modules\shop\controllers\IndexController::getPayProtocol($request, true),'getPayProtocol');
  295. //判断是否开启下单提示使用优惠券
  296. $this->dataIntegrated($this->getCouponSet($request, true), 'getCouponSet');
  297. $this->dataIntegrated($this->getStoreSearch($request, true), 'storeSearch');
  298. //运费说明
  299. $this->dataIntegrated($this->getFreightExplain($request,true),'freightExplain');
  300. //配送时间
  301. $this->dataIntegrated($this->deliveryTime($request,true),'deliveryTime');
  302. return $this->successJson('', $this->apiData);
  303. }
  304. private function getStoreSearch(Request $request, $integrated = null)
  305. {
  306. $data=[];
  307. if(app('plugins')->isEnabled('store-search'))
  308. {
  309. $store_search_set = \Setting::get('plugin.store-search');
  310. if($store_search_set['is_open_but'])
  311. {
  312. $data =[
  313. 'is_open_but'=>$store_search_set['is_open_but'],
  314. 'but_title'=> $store_search_set['but_title'],
  315. 'web_url'=>$store_search_set['web_url'],
  316. 'app_url'=>$store_search_set['app_url'],
  317. ];
  318. }
  319. }
  320. if(is_null($integrated))
  321. {
  322. return $this->successJson('ok',$data);
  323. }
  324. else
  325. {
  326. return show_json(1,$data);
  327. }
  328. }
  329. private function getFreightExplain(Request $request, $integrated = null)
  330. {
  331. $shopOrderSet = \Setting::get('shop.order');
  332. $freightExplainSet = [
  333. 'is_freight_explain' => $shopOrderSet['is_freight_explain'] ?? 0,
  334. 'freight_explain_content' => explode("\n",$shopOrderSet['freight_explain_content']) ?? []
  335. ];
  336. if (is_null($integrated)) {
  337. return $this->successJson('ok',$freightExplainSet);
  338. } else {
  339. return show_json(1,$freightExplainSet);
  340. }
  341. }
  342. private function goTaxRate()
  343. {
  344. $goods_id = request()->input('goods_id');
  345. $good_tax_rate = InvoiceRelation::uniacid()->where('goods_id', $goods_id)->pluck('tax_rate');
  346. $good_tax_rate = empty($good_tax_rate) ? [] : array_unique($good_tax_rate->toArray());
  347. if (!$good_tax_rate) {
  348. $category_id = GoodsCategory::where('goods_id', $goods_id)->pluck('category_id');
  349. $category_id = empty($category_id) ? [] : $category_id->toArray();
  350. if ($category_id) {
  351. $good_tax_rate = InvoiceCategory::uniacid()->where('category_id', $category_id)->pluck('tax_rate');
  352. $good_tax_rate = empty($good_tax_rate) ? [] : array_unique($good_tax_rate->toArray());
  353. }
  354. }
  355. return $good_tax_rate;
  356. }
  357. }