FyySqlServerService.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace App\Service;
  3. use App\Model\SaleOrdersProduct;
  4. use Illuminate\Support\Facades\DB;
  5. class FyySqlServerService extends Service
  6. {
  7. public $db = null;
  8. public function __construct()
  9. {
  10. $domain_name = $_SERVER['HTTP_HOST'];
  11. if(! $this->db) $this->db = DB::connection('sqlsrvs');
  12. }
  13. private function fakeData(){
  14. $return = [
  15. [
  16. 'out_order_no' => '001',
  17. 'out_order_no_time' => 1685928995,
  18. 'customer_no' => '201603012',
  19. 'customer_name' => '巴大胡',
  20. 'table_header_mark' => '表头备注',
  21. 'product_no' => '产品编码001',
  22. 'product_title' => '产品名称001',
  23. 'product_size' => '产品规格30c',
  24. 'product_unit' => '产品单位米',
  25. 'order_quantity' => 100,
  26. 'product_quantity_on_hand' => 50,
  27. 'technology_material' => '工艺材质',
  28. 'technology_name' => '工艺名称:同命',
  29. 'wood_name' => '木皮名称:梭梭树皮',
  30. 'process_mark' => '加工备注',
  31. 'table_body_mark' => '表体备注',
  32. 'out_crt_man' => '外部人员一',
  33. 'out_checker_man' => '外部人员二',
  34. 'out_checker_time' => 1685928995,
  35. ],
  36. [
  37. 'out_order_no' => '001',
  38. 'out_order_no_time' => 1685928995,
  39. 'customer_no' => '201603012',
  40. 'customer_name' => '巴大胡',
  41. 'table_header_mark' => '表头备注',
  42. 'product_no' => '产品编码002',
  43. 'product_title' => '产品名称002',
  44. 'product_size' => '产品规格30d',
  45. 'product_unit' => '产品单位米',
  46. 'order_quantity' => 100,
  47. 'product_quantity_on_hand' => 50,
  48. 'technology_material' => '工艺材质',
  49. 'technology_name' => '工艺名称:同命',
  50. 'wood_name' => '木皮名称:梭梭树皮',
  51. 'process_mark' => '加工备注',
  52. 'table_body_mark' => '表体备注',
  53. 'out_crt_man' => '外部人员一',
  54. 'out_checker_man' => '外部人员二',
  55. 'out_checker_time' => 1685928995,
  56. ],
  57. [
  58. 'out_order_no' => '002',
  59. 'out_order_no_time' => 1685928995,
  60. 'customer_no' => '201603012',
  61. 'customer_name' => '巴大胡',
  62. 'table_header_mark' => '表头备注',
  63. 'product_no' => '产品编码002',
  64. 'product_title' => '产品名称002',
  65. 'product_size' => '产品规格30d',
  66. 'product_unit' => '产品单位米',
  67. 'order_quantity' => 100,
  68. 'product_quantity_on_hand' => 50,
  69. 'technology_material' => '工艺材质',
  70. 'technology_name' => '工艺名称:同命',
  71. 'wood_name' => '木皮名称:梭梭树皮',
  72. 'process_mark' => '加工备注',
  73. 'table_body_mark' => '表体备注',
  74. 'out_crt_man' => '外部人员一',
  75. 'out_checker_man' => '外部人员二',
  76. 'out_checker_time' => 1685928995,
  77. ],
  78. ];
  79. return $return;
  80. }
  81. //获取数据(点击引入)
  82. public function getDataFromSqlServer($data){
  83. if(empty($data['out_order_no_time'][0]) || empty($data['out_order_no_time'][1])) return [false,'制单日期不能为空!',''];
  84. //查询产品主表副表数据
  85. date_default_timezone_set("PRC");
  86. $start = date('Y-m-d H:i:s.000',$data['out_order_no_time'][0]);
  87. $end = date('Y-m-d H:i:s.000',$data['out_order_no_time'][1]);
  88. $model = $this->db->table('SO_SOMain as a')
  89. ->leftJoin('SO_SODetails as b','b.cSOCode','a.cSOCode')
  90. ->whereBetween('a.dDate',[$start, $end])
  91. ->select('a.cSOCode as out_order_no','a.dDate as out_order_no_time','a.cCusCode as customer_no','a.cCusName as customer_name','a.cMemo as table_header_mark','a.cMaker as out_crt_man','a.cVerifier as out_checker_man','a.dverifydate as out_checker_time','b.cInvCode as product_no','b.iQuantity as order_quantity','b.cDefine28 as technology_material','b.cFree1 as technology_name','b.cFree2 as wood_name','b.cDefine30 as process_mark','b.cMemo as table_body_mark');
  92. if(! empty($data['out_order_no'])) $model->where('a.cSOCode', 'LIKE', '%'.$data['out_order_no'].'%');
  93. if(! empty($data['customer_no'])) $model->where('a.cCusCode', 'LIKE', '%'.$data['customer_no'].'%');
  94. if(! empty($data['customer_name'])) $model->where('a.cCusName', 'LIKE', '%'.$data['customer_name'].'%');
  95. if(! empty($data['table_header_mark'])) $model->where('a.cMemo', 'LIKE', '%'.$data['table_header_mark'].'%');
  96. if(! empty($data['out_crt_man'])) $model->where('a.cMaker', 'LIKE', '%'.$data['out_crt_man'].'%');
  97. if(! empty($data['out_checker_man'])) $model->where('a.cVerifier', 'LIKE', '%'.$data['out_checker_man'].'%');
  98. if(! empty($data['out_checker_time'][0]) && ! empty($data['out_checker_time'][1])) {
  99. $start1 = date('Y-m-d H:i:s.000',$data['out_checker_time'][0]);
  100. $end1 = date('Y-m-d H:i:s.000',$data['out_checker_time'][1]);
  101. $model->whereBetween('a.dverifydate',[$start1, $end1]);
  102. }
  103. $result = $model->get()->toArray();
  104. if(empty($result)) return [false,'暂无数据,更新结束!',''];
  105. //查询附带的一些信息(比较少)
  106. $product_no = array_column($result,'product_no');
  107. $messageOne = $this->db->table('Inventory as a')
  108. ->join('ComputationUnit as b',function($join){
  109. $join->on('a.cGroupCode','=','b.cGroupCode')
  110. ->on('a.cComUnitCode','=','b.cComUnitCode');
  111. }, null,null,'left')
  112. ->whereIn('a.cInvCode',$product_no)
  113. ->select('a.cInvCode as product_no','a.cInvName as product_title','a.cInvStd as product_size','b.cComUnitName as product_unit')
  114. ->get()->toArray();
  115. $messageMap = array_column($messageOne,null,'product_no');
  116. //现存量查询开始 ---组织查询条件
  117. $args = '';
  118. foreach ($result as $value){
  119. $product = $value->product_no;
  120. $technology_name = $value->technology_name ?? '';
  121. $wood_name = $value->wood_name ?? '';
  122. $args .= "(a.cInvCode = '{$product}' and a.cFree1 = '{$technology_name}' and a.cFree2 = '{$wood_name}') OR ";
  123. }
  124. $args = rtrim($args,'OR ');
  125. $messageTwo = $this->db->table('CurrentStock as a')
  126. ->leftJoin('Warehouse as b','b.cWhCode','a.cWhCode')
  127. ->whereRaw("($args)")
  128. ->where('a.iQuantity','>',0)
  129. ->select('a.iQuantity as product_quantity_on_hand','a.cInvCode as product_no','a.cFree1 as technology_name','a.cFree2 as wood_name','b.cWhName as warehouse_name')
  130. ->get()->toArray();
  131. if(! empty($messageTwo)){
  132. foreach ($messageTwo as $key => $value){
  133. $messageTwo[$key] = (array)$value;
  134. }
  135. }
  136. //现存量查询结束
  137. foreach ($result as $key => $value){
  138. $keys = $value->product_no . $value->technology_name . $value->wood_name;
  139. $result[$key]->out_order_no_time = $value->out_order_no_time ? strtotime($value->out_order_no_time) : 0;
  140. $result[$key]->out_checker_time = $value->out_checker_time ? strtotime($value->out_checker_time) : 0;
  141. $result[$key]->product_title = $messageMap[$value->product_no]->product_title ?? '';
  142. $result[$key]->product_size = $messageMap[$value->product_no]->product_size ?? '';
  143. $result[$key]->product_unit = $messageMap[$value->product_no]->product_unit ?? '';
  144. $result[$key] = (array)$value;
  145. }
  146. return [true,$result,$messageTwo];
  147. }
  148. //获取数据(刷新现存量)
  149. public function getDataFromSqlServerForOnHand($data){
  150. if(empty($data['id'])) return [false,'数据不能为空!',''];
  151. $product = SaleOrdersProduct::whereIn('id',$data['id'])
  152. ->select('product_no','technology_name','wood_name')
  153. ->get()->toArray();
  154. //现存量查询开始 ---组织查询条件
  155. $args = '';
  156. foreach ($product as $value){
  157. $args .= "(a.cInvCode = '{$value['product_no']}' and a.cFree1 = '{$value['technology_name']}' and a.cFree2 = '{$value['wood_name']}') OR ";
  158. }
  159. $args = rtrim($args,'OR ');
  160. $message = $this->db->table('CurrentStock as a')
  161. ->leftJoin('Warehouse as b','b.cWhCode','a.cWhCode')
  162. ->whereRaw("($args)")
  163. ->where('a.iQuantity','>',0)
  164. ->select('a.iQuantity as product_quantity_on_hand','a.cInvCode as product_no','a.cFree1 as technology_name','a.cFree2 as wood_name','b.cWhName as warehouse_name')
  165. ->get()->toArray();
  166. if(! empty($message)){
  167. foreach ($message as $key => $value){
  168. $message[$key] = (array)$value;
  169. }
  170. }
  171. //现存量查询结束
  172. return [true,$message,$product];
  173. }
  174. }