GoodsPrivilegeService.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/2/22
  6. * Time: 19:41
  7. */
  8. namespace app\backend\modules\goods\services;
  9. class GoodsPrivilegeService
  10. {
  11. public static function tpl_form_field_date($name, $value = '', $withtime = false)
  12. {
  13. $html = '';
  14. if (!defined('TPL_INIT_DATA')) {
  15. $html = '
  16. <script type="text/javascript">
  17. require(["datetimepicker"], function(){
  18. $(function(){
  19. $(".datetimepicker").each(function(){
  20. var option = {
  21. lang : "zh",
  22. step : "30",
  23. timepicker : ' . (!empty($withtime) ? "true" : "false") .
  24. ',closeOnDateSelect : true,
  25. format : "Y-m-d' . (!empty($withtime) ? ' H:i:s"' : '"') .
  26. '};
  27. $(this).datetimepicker(option);
  28. });
  29. });
  30. });
  31. </script>';
  32. define('TPL_INIT_DATA', true);
  33. }
  34. $withtime = empty($withtime) ? false : true;
  35. if (!empty($value)) {
  36. $value = strexists($value, '-') ? strtotime($value) : $value;
  37. } else {
  38. $value = TIMESTAMP;
  39. }
  40. $value = ($withtime ? date('Y-m-d H:i:s', $value) : date('Y-m-d', $value));
  41. $html .= '<input type="text" name="' . $name . '" value="' . $value . '" placeholder="请选择日期时间" class="datetimepicker form-control" style="padding-left:12px;" />';
  42. return $html;
  43. }
  44. }